nhibernate-projections

LINQ-to-NHibernate: Cannot use Linq Skip() and Take() with FetchMany

匆匆过客 提交于 2019-12-14 02:06:54
问题 I have these entities: public class BlogPost { public virtual int Id { get; set; } public virtual IList<Keyword> Keywords { get; set; } public virtual IList<BlogComment> Comments { get; set; } } public class BlogComment { public virtual int Id { get; set; } public virtual BlogPost Post { get; set; } } public class Keyword { public virtual int Id { get; set; } public virtual IList<BlogPost> BlogPosts { get; set; } } I want to load a paged-list of BlogPost s by their Keyword s and comments

NHibernate Criteria select items by the group by and sum of itemid within another table

夙愿已清 提交于 2019-12-12 12:16:53
问题 public class SearchText { public virtual int Id { get; set; } public virtual string Text { get; set; } } public class SearchTextLog { public virtual int Id { get; set; } public virtual SearchText SearchText { get; set; } public virtual User User { get; set; } public virtual int SearchCount { get; set; } public virtual DateTime LastSearchDate { get; set; } } I am trying to select the top 5 SearchText items based on the sum of their count within the SearchTextLog. Currently I have only been

NHibernate - Querying from a collection of Value Types (non-Entity) to solve Select N+1

霸气de小男生 提交于 2019-12-12 03:54:34
问题 I have an entity that represents a Tweet from Twitter like so: public class Tweet { public virtual long Id { get; set; } public virtual string Username { get; set; } public virtual string Message { get; set; } // other properties (snip)... public virtual ISet<long> VoterIds { get; protected set; } } I'm trying to run a query in NHibernate that selects a list of tweets with an additional column that denotes whether a particular user by their UserId has voted for each Tweet. When I user votes

Using in-built sql “Convert” function in nhibernate criteria

这一生的挚爱 提交于 2019-12-11 02:59:45
问题 I want to make use of the Convert function in SQL Server 2008 so I can search on a DateTime column. The proposed SQL would look something like this: SELECT (list of fields) FROM aTable WHERE CONVERT(VARCHAR(25), theColumn) LIKE '%2009%' Here is part of the criteria that tries to emulate the call to convert: Projections.SqlFunction("CONVERT", NHibernateUtil.String, Projections.Constant("varchar(25)"), Projections.Property(searchCol)) The search column would be dynamically selected so it cannot

Nhibernate count distinct (based on multiple columns)

杀马特。学长 韩版系。学妹 提交于 2019-12-03 18:10:00
问题 Basically, i have been trying to do this (count distinct based on two columns): select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB))) from TableA left outer join TableB on TableA.TableBId = TableB.Id where PropertyA like '%123%' Been googling on how to do this but with no luck. Tried this, but never actually worked. This does not count distinctly based on the two properties from two tables: var queryOver = c.QueryOver<TableA>(); TableB tableBAlias = null; TableA tableAAlias =

When to use Hibernate projections?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 01:39:33
问题 I am a little confused about Hibernate's projections and criteria . When to use projections and when to use criteria? 回答1: They're not mutually exclusive, you can use both at the same time. Projections are generally used in the context of some Criteria. To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate

When to use Hibernate projections?

这一生的挚爱 提交于 2019-12-02 15:07:12
I am a little confused about Hibernate's projections and criteria . When to use projections and when to use criteria? They're not mutually exclusive, you can use both at the same time. Projections are generally used in the context of some Criteria. To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate functions like max , sum and so on. It's like referring to which data you're fetching. Like modifying the select

Project Collection in NHibernate

落爺英雄遲暮 提交于 2019-12-02 11:06:28
问题 Is it possible that I can project collection in NHibernate? For Example: User { UserGuid, IList<Groups> UserGroups, } User userEntity = null; _session .StatefulSession.QueryOver(() => userEntity) .SelectList(list => list .Select(x => x.UserGuid).WithAlias(() => userEntity.UserGuid) //How can I project group collection here? .Select(x => x.Groups).WithAlias(() => userEntity.Groups) ) .TransformUsing(Transformers.AliasToBean<UserEntity>()) .List(); 回答1: We have to thing about projection as a

Project Collection in NHibernate

删除回忆录丶 提交于 2019-12-02 06:05:39
Is it possible that I can project collection in NHibernate? For Example: User { UserGuid, IList<Groups> UserGroups, } User userEntity = null; _session .StatefulSession.QueryOver(() => userEntity) .SelectList(list => list .Select(x => x.UserGuid).WithAlias(() => userEntity.UserGuid) //How can I project group collection here? .Select(x => x.Groups).WithAlias(() => userEntity.Groups) ) .TransformUsing(Transformers.AliasToBean<UserEntity>()) .List(); Radim Köhler We have to thing about projection as a single SELECT clause. What we would be able to do with it on a DB side, we can mimic with

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;}