nhibernate-criteria

Incorrect Syntax near “?” : Nhibernate Generated Query

蹲街弑〆低调 提交于 2019-12-02 05:24:34
问题 I am getting problem while working with positional parameters in Nhbernate. Criteria GroupProperty is emitting sql with both named and positional variables. This statement: session.CreateCriteria(typeof(MatchStageFrom)) .SetProjection(Projections.GroupProperty( Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("LastName"), Projections.Constant(0), Projections.Constant(1)) ) ); is producing this SQL: SELECT substring(this_.LAST_NAME, @p0, @p1) as y0_ FROM MATCH

NHibernate Criteria: Subquery After 'From' Clause

杀马特。学长 韩版系。学妹 提交于 2019-12-02 02:45:18
问题 How can I write the following SQL using Criteria: select b.Name as Batch, b.Capacity as Capecity, a.tStudent as Admit, (b.Capacity-a.tStudent) as Availabe from ( SELECT count(Id) as tStudent, BatchId FROM [dbo].[Student] group by BatchId) as a left join [dbo].[Batch] as b on a.BatchId = b.Id 回答1: To use NHibernate, to produce query like this: SELECT ... FROM ( SELECT ... ) AS a .. We have to options: Map the sub-select as an Entity. create raw SQL query The first option would mean to create

NHibernate Criteria: Subquery After 'From' Clause

与世无争的帅哥 提交于 2019-12-02 01:19:56
How can I write the following SQL using Criteria: select b.Name as Batch, b.Capacity as Capecity, a.tStudent as Admit, (b.Capacity-a.tStudent) as Availabe from ( SELECT count(Id) as tStudent, BatchId FROM [dbo].[Student] group by BatchId) as a left join [dbo].[Batch] as b on a.BatchId = b.Id To use NHibernate, to produce query like this: SELECT ... FROM ( SELECT ... ) AS a .. We have to options: Map the sub-select as an Entity. create raw SQL query The first option would mean to create some view , and map it as an Entity. If we do not like view (or cannot create it) we can use the power of

Nhibernate projection with child collection

假如想象 提交于 2019-12-01 11:35:11
Using NHibernate 2.1, I'm trying to project an entity and its child collection into a DTO. My entity looks like this.. public class Application { public int Id {get;set;} public string Name {get;set;} public List<ApplicationSetting> Settings {get;set;} // A bunch of other properties that I don't want in the DTO } public class ApplicationSetting { public int Id {get;set;} public string Name {get;set;} public string Code {get;set;} // A bunch of other properties that I don't want in the DTO } My DTO looks like this.. public ApplicationDto { public int Id {get;set;} public string Name {get;set;}

Nhibernate projection with child collection

喜你入骨 提交于 2019-12-01 10:06:46
问题 Using NHibernate 2.1, I'm trying to project an entity and its child collection into a DTO. My entity looks like this.. public class Application { public int Id {get;set;} public string Name {get;set;} public List<ApplicationSetting> Settings {get;set;} // A bunch of other properties that I don't want in the DTO } public class ApplicationSetting { public int Id {get;set;} public string Name {get;set;} public string Code {get;set;} // A bunch of other properties that I don't want in the DTO }

How can QueryOver be used to filter for a specific class?

非 Y 不嫁゛ 提交于 2019-12-01 08:05:24
I am currently dynamically constructing queries like so: QueryOver<Base, Base> q = QueryOver.Of<Base>(); if (foo != null) q = q.Where(b => b.Foo == foo); // ... Now there are multiple mapped subclasses of Base (e. g. Derived ) which I want to filter on, basically something like: if (bar) q = q.Where(b => b is Derived); // does not work or: if (bar) q = q.Where(b => b.DiscriminatorColumn == 'derived'); // dito How do I best achieve that, preferably - but not neccessarily - in a type-safe way? Can this be done using LINQ, too? This is not intuitive, but the following should work fine (QueryOver)

How can QueryOver be used to filter for a specific class?

邮差的信 提交于 2019-12-01 04:36:59
问题 I am currently dynamically constructing queries like so: QueryOver<Base, Base> q = QueryOver.Of<Base>(); if (foo != null) q = q.Where(b => b.Foo == foo); // ... Now there are multiple mapped subclasses of Base (e. g. Derived ) which I want to filter on, basically something like: if (bar) q = q.Where(b => b is Derived); // does not work or: if (bar) q = q.Where(b => b.DiscriminatorColumn == 'derived'); // dito How do I best achieve that, preferably - but not neccessarily - in a type-safe way?

How to resolve poor nHibernate collection initialization

无人久伴 提交于 2019-12-01 01:03:53
nHibernate3; retrieving 4xxx records out of an EAV data schema. When nHibernate, or .NET, goes to initialize those collections for the first time, we're seeing a severe penalty. Subsequent calls appear to perform more efficiently. Running the same queries in SQL Server Management Studio result in expected quick return times. Using Fluent and runtime mapping instead of .hbm.xml; curious if serialized mapping would help here? nHibernate Profiler and log4net logging didn't seem to give me much to go on. A total of something like 140,000 entities are hydrated in this process. Attached a screenshot

How to resolve poor nHibernate collection initialization

匆匆过客 提交于 2019-11-30 20:39:31
问题 nHibernate3; retrieving 4xxx records out of an EAV data schema. When nHibernate, or .NET, goes to initialize those collections for the first time, we're seeing a severe penalty. Subsequent calls appear to perform more efficiently. Running the same queries in SQL Server Management Studio result in expected quick return times. Using Fluent and runtime mapping instead of .hbm.xml; curious if serialized mapping would help here? nHibernate Profiler and log4net logging didn't seem to give me much

Fetching Paginated Entity with Collection

99封情书 提交于 2019-11-29 16:47:24
Consider two entities Person which has a one-to-many collection Vehicles public class Person { public IList<Vehicle> Vehicles { get; set;} } public class Vehicle { public string Name { get; set;} public Person Owner { get; set; } } I display a grid of Persons having vehicle and show the name of the first vehicle in the grid. The grid is paginated. I use the following criteria to fetch the data I have a criteria for loading data for a grid view as var criteria = DetachedCriteria.For<Person>() .CreateAlias("Vehicles","vehicle", JoinType.InnerJoin) .SetResultTransformer(new