icriteria

NHibernate Projections to retrieve a Collection?

我与影子孤独终老i 提交于 2019-12-11 16:41:59
问题 I´m having some trouble retrieving a collection of strings in a projection: say that I have the following classes public class WorkSet { public Guid Id { get; set; } public string Title { get; set; } public ISet<string> PartTitles { get; protected set; } } public class Work { public Guid Id { get; set; } public WorkSet WorkSet { get; set; } //a bunch of other properties } I then have a list of Work ids I want to retrieve WorkSet.Title, WorkSet.PartTitles and Id for. My tought was to do

NHibernate many-to-many criteria

你说的曾经没有我的故事 提交于 2019-12-11 09:06:16
问题 I have a list of questions, each linked to a list of tag. And the following data : Question1 : Tag1 Question2 : Tag1, Tag2 Question3 : Tag1, Tag2, Tag3 Question4 : Tag1, Tag3 The following criteria : var tagsIds = new int[] { tag1, tag2 }; var res = session.CreateCriteria<Question>() .CreateCriteria( "Tags" ) .Add( Restrictions.In( "id", tagsIds ) ) .List<Question>(); returns (I understand why, the "in" acts like an OR) Question1, Question2, Question3, Question4 Or I would like to get only

Does criteria.List(Type) transaction management

妖精的绣舞 提交于 2019-12-11 04:28:52
问题 Does this (not CRUD, but only Read) code require me to write transaction management? ICriteria criteria = SessionFactory.GetCurrentSession().CreateCriteria(EntityType); criteria.List<BaseEntity>(); 回答1: I cannot say that I do it always, But I would say that this question is pretty reasonable. As you can Transactions for read-only DB access? what we can get is: Transaction are required for read-only operations if you want to set a specific timeout for queries other than the default timeout, or

Equals conditions in outer joins with NHibernate ICriteria/QueryOver query

走远了吗. 提交于 2019-12-11 03:02:33
问题 How do I do a equals condition in an outer join in Nhibernate/QueryOver/ICriteria? The only way I have found to compare surveyRequest.Survey.Id with surveyID below is with IsIn . SystemUser systemUser= null; SurveyRequests surveyRequest = null; var query = Session.QueryOver<SystemUser>(() => systemUser) .Left.JoinAlias( () => systemUser.SurveyRequests, () => surveyRequest, Restrictions.On(()=>surveyRequest.Survey.Id).IsIn(new object []{surveyID })) // ^^^^ (I am reusing an earlier query

How to query a subproperty with NHibernate’s criteria api and the entity to load only the subproperties matching a predicate condition

ⅰ亾dé卋堺 提交于 2019-12-10 17:06:56
问题 Assuming the following: public class Order { public virtual int OrderId {get;set} public virtual ISet<Product> Products {get;set} } public class Product { public virtual int ProductId {get;set} public virtual string ProductName {get;set} } How would you query using the criteria api so that only an order with a specific orderid is returned and its Product collection should also be filtered down to Products whose Name start with the lettter P? 回答1: I would go about this with a DetachedCriteria:

NHLambdaExtensions: Create a Criterion object to add to ICriteria later

落花浮王杯 提交于 2019-12-08 02:15:18
问题 My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g: ICriterion criterion = Restrictions.Eq("Name", "John"); ...... detachedCriteriaSomewhereElse.Add(criterion); How do I do this in NHLambdaExtensions? what I really need to do is ICriterion criterion = Restrictions.Eq<Person>(p=> p.Name == "John"); but this isn't valid. Is there any way to do this? 回答1: With the NHLambdaExtensions you have the SQLExpression class that lets you

Removing Order from NHibernate Criteria Query

有些话、适合烂在心里 提交于 2019-12-07 17:43:34
问题 I have a criteria query that I am using to show pages of results. I also need to obtain the total count of all items. Rather than have two queries, one for paging the results and one for the count (since they are identical apart from the .AddOrder() public ICriteria StandardQuery { get { return NHibernateSesssionManager.GetSession.CreateCriteria<Person>.AddOrder("OrderProperty", Order.Desc); } public ICriteria CountQuery { get{ return StandardQuery.SetProjection(Projections.Count("ID")); }

HQL “Contains” statement howto?

浪子不回头ぞ 提交于 2019-12-07 17:31:38
问题 I have an entity that has a string property called Tags. I would like to query this entity based upon if a certain string is located in Tags property. So for example, I would have a function IList GetEntityByTag(string tag), this would return all Entity's that have the value of tag in their 'Tags' property. I tried going through the ICriteria approach... Expression.In(PropertyName, Value) but this is the exact opposite. I need something like Expression.In(Value, PropertyName). Perhaps IQuery

NHibernate: Convert an ICriteria to a DetachedCriteria

笑着哭i 提交于 2019-12-07 17:04:09
问题 Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using: .Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery)) Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference. 回答1: Following on from mattk's answer, you can inherit DetachedCriteria to access its constructors: public class ConvertedDetachedCriteria : DetachedCriteria { public ConvertedDetachedCriteria

NHibernate Lambda Extensions - Eager Loading a collection's assosciations

三世轮回 提交于 2019-12-06 16:57:02
问题 I've got a Criteria Query for a social networking site. A Person object has a collection of Friends (also person objects). The query grabs the first N friends, but I also want to eager load an associated object MainProfileImage and then a subsequent associated object MediumThumbnail. I can do this in HQL easily: select friends from Person person inner join person.Friends friends inner join fetch friends.MainProfileImage image inner join fetch image.MediumThumbnail where person = :person1