nhibernate-criteria

NHibernate: How to select the root entity in a projection

自闭症网瘾萝莉.ら 提交于 2019-12-10 14:29:50
问题 Ayende describes a really great way to get page count, and a specific page of data in a single query here: http://ayende.com/blog/2334/paged-data-count-with-nhibernate-the-really-easy-way His method looks like: IList list = session.CreateQuery("select b, rowcount() from Blog b") .SetFirstResult(5) .SetMaxResults(10) .List(); The only problem is this example is in HQL, and I need to do the same thing in an ICriteria query. To achieve the equivalent with ICriteria, I need to do something like:

Querying with nHibernate where todays date is between publishDate and Expiry date

早过忘川 提交于 2019-12-09 11:29:32
问题 I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime The expiry date can be null so I need to allow for that. I found a couple of examples here and here but they seem to work in a different way and accept 2 values and compare to one DB field. I want the other way wrong really. Query so far: var query = _session.CreateCriteria<Message>() .AddOrder(Order.Desc("PublishedDateTime

NHibernate child collection Projection to DTO

倖福魔咒の 提交于 2019-12-07 22:30:35
问题 I have had a good look around for answers on this, and several questions suggest this cannot be done. Nhibernate projection with child collection NHibernate QueryOver projections - projecting collections to DTO NHibernate Projections - how to project collections So I was wondering what would be a good work around to project a child collection to my DTO. Will I need to run two seperate projections and manually add the children to the parent? I am using NH 3.3.1 I have the following DTO data

How can I select a column within a dictionary value with nhibernate?

纵然是瞬间 提交于 2019-12-07 19:41:39
问题 I have structure similar to this: public class Entity { public int Id { get; set; } public IDictionary<string, EntityLocale> Locales { get; set; } } public class EntityLocale { public string Name { get; set; } } public class EntityMap : ClassMap<Entity> { public EntityMap() { HasMany(x => x.Locales) .AsMap<string>("Locale") .Component( c => { c.Map(x => x.Name); } ); } } And I want to recieve all names of product locales with a "en" key. With linq it will be: var names = Session.QueryOver

NHibernate converting string parameters to nvarchar instead of varchar. How can I stop this?

南笙酒味 提交于 2019-12-07 18:04:58
问题 I have a class mapped to a view and am searching on first and last names in order to search for patient records. The view ultimately looks at the first and last name fields on the patient table (possibly others as well depending on input). When the criteria converts to SQL, it's entering my strings as nvarchar parameters. I've already used type="AnsiString" and length="50" on my mapping, but it still is converting these to nvarchar, which is causing a performance hit on my query. <class name=

Set TimeOut Expired in NHibernate

て烟熏妆下的殇ゞ 提交于 2019-12-07 04:25:02
问题 I have a stored procedure in sql server 2008 R2 which was working fine, but suddenly it throws an exception of TimeOut Expiration. BmDaoSession.CreateSQLQuery("exec SP_Name @Param1 = '" + clientCode + "', @Param2 ='" + existingDatabase + "', @Flag='" + flag + "'").ExecuteUpdate(); I am using the above NHibernate command to call my SP. My question is how Can I set the TimeOut Expiration in NHibernate. Thanks 回答1: Just add fluently SetTimeout method: BmDaoSession.CreateSQLQuery("exec SP_Name

NHibernate - easiest way to do a LIKE search against an integer column with Criteria API?

余生长醉 提交于 2019-12-06 19:59:57
问题 I'm trying to do a like search against an integer column, what I need to do is actually cast the column to a varchar and then do the like search. Is this possible? what's the easiest way to do this using the Criteria API? var search = "123"; criteria.Add(Restrictions.Like("Number", "%" + search + "%")) 回答1: If Number were a string, then it would be easy : .Add(Restrictions.Like("Number", "some_value",MatchMode.Anywhere)) Since you have a number, NHibernate will check the type of Number and if

Union with NHibernate and Criteria?

隐身守侯 提交于 2019-12-06 16:55:00
Union with NHibernate and Criteria: Is it possible in Criteria or QueryOver? If not, is there any other way to achieve a union of two result within the same query? eulerfx You can't do a union directly, but you can do two future queries and union the results in code: var resultSet1 = this.Session.CreateCriteria<A>().Future<A>(); var resultSet2 = this.Session.CreateCriteria<B>().Future<B>(); After this, when either result set is enumerated, NHibernate will issue a single query to the database which will return multiple result sets. Note, if you are not using SQL Server, the database may not

NHibernate child collection Projection to DTO

自古美人都是妖i 提交于 2019-12-06 08:12:02
I have had a good look around for answers on this, and several questions suggest this cannot be done. Nhibernate projection with child collection NHibernate QueryOver projections - projecting collections to DTO NHibernate Projections - how to project collections So I was wondering what would be a good work around to project a child collection to my DTO. Will I need to run two seperate projections and manually add the children to the parent? I am using NH 3.3.1 I have the following DTO data structure public class ProviderDto { public int Id { get; set; } public string Name { get; set; } public

How can I select a column within a dictionary value with nhibernate?

江枫思渺然 提交于 2019-12-06 06:01:30
I have structure similar to this: public class Entity { public int Id { get; set; } public IDictionary<string, EntityLocale> Locales { get; set; } } public class EntityLocale { public string Name { get; set; } } public class EntityMap : ClassMap<Entity> { public EntityMap() { HasMany(x => x.Locales) .AsMap<string>("Locale") .Component( c => { c.Map(x => x.Name); } ); } } And I want to recieve all names of product locales with a "en" key. With linq it will be: var names = Session.QueryOver<Product>().List().Select(x => x.Locales["en"].Name).ToList(); How do I achieve this with nhibernate? (I