本文整理汇总了C#中ISession.CreateCriteria方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.CreateCriteria方法的具体用法?C# ISession.CreateCriteria怎么用?C# ISession.CreateCriteria使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.CreateCriteria方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsExistsCode
private void IsExistsCode(ISession session, RentOrderDetail rentOrderDetail)
{
ICriteria criteria = session.CreateCriteria(typeof(RentOrderDetail));
ICriterion criterion = null;
if (rentOrderDetail.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(rentOrderDetail.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("RentOrderID", rentOrderDetail.RentOrder);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.RentOrderIsExistsException();//领用明细单号已经存在
}
}
示例2: Init
public void Init() {
_session = _sessionFactory.OpenSession();
foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
foreach (var killRecord in _session.CreateCriteria(killType).List()) {
_session.Delete(killRecord);
}
}
_session.Flush();
_session.Close();
_session.Dispose();
_session = _sessionFactory.OpenSession();
var builder = new ContainerBuilder();
builder.RegisterAutoMocking();
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(SettingsFormatter)).As(typeof(ISettingsFormatter));
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(_transactionManager = new TestTransactionManager(_session)).As<ITransactionManager>();
_container = builder.Build();
}
示例3: IsExists
private void IsExists(ISession session, StorageAlarm storageAlarm)
{
ICriteria criteria = session.CreateCriteria(typeof(StorageAlarm));
ICriterion criterion = null;
if (storageAlarm.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(storageAlarm.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("Storehouse", storageAlarm.Storehouse);
criteria.Add(criterion);
criterion = Restrictions.Eq("Goods", storageAlarm.Goods);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.StorageAlarmIsExistsException();//库存报警表存在
}
}
示例4: IsExists
private void IsExists(ISession session, SellPriceInfo spi)
{
ICriteria criteria = session.CreateCriteria(typeof(SellPriceInfo));
ICriterion criterion = null;
if (spi.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(spi.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("Storehouse", spi.Storehouse);
criteria.Add(criterion);
criterion = Restrictions.Eq("Goods", spi.Goods);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.SellPriceInfoIsExistsException();//销售价格管理(商品资料子表)已经存在
}
}
示例5: GetAll
public List<GroupFilter> GetAll(ISession session)
{
var gfs = session
.CreateCriteria(typeof(GroupFilter))
.List<GroupFilter>();
return new List<GroupFilter>(gfs);
}
示例6: IsExistsCode
private void IsExistsCode(ISession session, Employee emp)
{
ICriteria criteria = session.CreateCriteria(typeof(Employee));
ICriterion criterion = null;
if (emp.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(emp.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("Code", emp.Code);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.EmpCodeIsExistsException();//部门Code已经存在
}
}
示例7: GetSum
private decimal GetSum(ISession session, Guid accountId, DateTime date, EntryType entryType)
{
// TODO : try to get the lamda version working
// currently gives this error: "could not resolve property" regarding Transaction.Date
//return session.QueryOver<Entry>().Where(x =>
// (x.Account.Id == accountId) &&
// (x.Transaction.Date <= date) &&
// (x.Type == entryType))
// .List()
// .Sum(x => x.Amount);
var entries = session.CreateCriteria<Entry>()
.Add(Expression.Eq("Type", entryType))
.Add(Expression.Eq("Account.Id", accountId))
.CreateCriteria("Transaction")
.Add(Expression.Eq("Deleted", false))
.Add(Expression.Le("Date", date))
.List();
decimal sum = 0;
foreach (Entry entry in entries)
{
sum += entry.Amount;
}
return sum;
}
示例8: Init
public void Init() {
var builder = new ContainerBuilder();
builder.RegisterAutoMocking();
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
_container = builder.Build();
_container.Mock<ISessionLocator>()
.Setup(x => x.For(It.IsAny<Type>()))
.Returns(() => _session);
_session = _sessionFactory.OpenSession();
foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
foreach (var killRecord in _session.CreateCriteria(killType).List()) {
_session.Delete(killRecord);
}
}
_session.Flush();
}
示例9: GetReferrerSearchQuery
public ReferrerSearchQuery GetReferrerSearchQuery(ISession session)
{
ReferrerSearchQuery rsq = null;
if (Id == 0)
{
rsq = (ReferrerSearchQuery)session.CreateCriteria(typeof(ReferrerSearchQuery))
.Add(Expression.Eq("SearchQuery", SearchQuery))
.UniqueResult();
if (rsq == null)
{
rsq = new ReferrerSearchQuery();
rsq.RequestCount = RequestCount;
}
else
{
rsq.RequestCount += RequestCount;
}
}
else
{
rsq = (ReferrerSearchQuery)session.Load(typeof(ReferrerSearchQuery), Id);
rsq.RequestCount = RequestCount;
}
rsq.SearchQuery = SearchQuery;
return rsq;
}
示例10: GetBrowser
public Browser GetBrowser(ISession session)
{
Browser browser = null;
if (Id == 0)
{
browser = (Browser)session.CreateCriteria(typeof(Browser))
.Add(Expression.Eq("Name", Name))
.Add(Expression.Eq("Platform", Platform))
.Add(Expression.Eq("Version", Version))
.UniqueResult();
if (browser == null)
{
browser = new Browser();
}
}
else
{
browser = (Browser) session.Load(typeof(Browser), Id);
}
browser.Name = Name;
browser.Version = Version;
browser.Platform = Platform;
return browser;
}
示例11: IsExistsCode
private void IsExistsCode(ISession session, CheckStockDetail checkStockDetail)
{
ICriteria criteria = session.CreateCriteria(typeof(CheckStockDetail));
ICriterion criterion = null;
if (checkStockDetail.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(checkStockDetail.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("CheckStockID", checkStockDetail.CheckStock);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.CheckStockIsExistsException();//盘点明细单号已经存在
}
}
示例12: IsExistsCode
private void IsExistsCode(ISession session, PurOrder pur)
{
ICriteria criteria = session.CreateCriteria(typeof(PurOrder));
ICriterion criterion = null;
if (pur.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(pur.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("PurOrderCode", pur.PurOrderCode);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.PurOrderIsExistsException();//采购主单号已经存在
}
}
示例13: IsExistsCode
private void IsExistsCode(ISession session, Storehouse sh)
{
ICriteria criteria = session.CreateCriteria(typeof(Storehouse));
ICriterion criterion = null;
if (sh.Id != Guid.Empty)
{
criterion = Restrictions.Not(Restrictions.IdEq(sh.Id));
criteria.Add(criterion);
}
criterion = Restrictions.Eq("StoreCode", sh.StoreCode);
criteria.Add(criterion);
//统计
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Count("Id"))
);
int count = (int)criteria.UniqueResult();
if (count > 0)
{
throw new EasyJob.Tools.Exceptions.StorehouseCodeIsExistsException();//库存Code已经存在
}
}
示例14: BuildCriteria
protected virtual ICriteria BuildCriteria(ISession session)
{
if (cachedCriteria == null)
{
if (detachedCriteria != null)
{
cachedCriteria = detachedCriteria.GetExecutableCriteria(session);
}
else
{
cachedCriteria = session.CreateCriteria(targetType);
if (criterions != null)
{
foreach (var queryCriteria in criterions)
{
cachedCriteria.Add(queryCriteria);
}
}
}
if (orders != null)
{
foreach (var order in orders)
{
cachedCriteria.AddOrder(order);
}
}
}
return cachedCriteria;
}
示例15: CreateObjects
protected void CreateObjects(System.Type rootClass, ISession session)
{
criteria = (CriteriaImpl) session.CreateCriteria(rootClass);
criteriaQuery = new CriteriaQueryTranslator(
(ISessionFactoryImplementor) factory,
criteria, criteria.EntityOrClassName, SqlAlias);
}