queryover

Nhibernate Linq query to QueryOver

落爺英雄遲暮 提交于 2019-12-31 03:44:04
问题 I have the following piece of code: 1: ids = GetAnArrayOfIds(); 2: jobEntities = jobEntities.Where(j => j.Locations.Select(l => l.Id).Any(ids.Contains)); How do I write 2 using QueryOver ? Thank you, 回答1: var results = session.QueryOver<Job>() .JoinQueryOver<Location>(u => u.Locations) .Where(loc => loc.Id.IsIn(ids)) .TransformUsing(Transformers.DistinctRootEntity) .List(); Hope this helps 来源: https://stackoverflow.com/questions/6997146/nhibernate-linq-query-to-queryover

Nhibernate + QueryOver: filter with Where ignoring sensitive

给你一囗甜甜゛ 提交于 2019-12-30 08:09:37
问题 I am trying to build a simple query in nHibernate with QueryOver but I want it to convert everything lower-case or ignore sensitive: Domain.User User = Session.QueryOver<Domain.User>() .Where(x=>x.Login=="username") .SingleOrDefault(); How can I achieve this? UPDATE : Someone suggested that the problem could be with the colletion of the DB but I've never had any kind of problem with that and this script works: Domain.User User = Session .CreateCriteria<Domain.User>() .Add(Expression.Eq("Login

How to create hibernate composite key using annotations

雨燕双飞 提交于 2019-12-28 05:07:09
问题 I am trying to use hibernate annotations to insert data to a MySQL database table which doesn't have a primary key defined. However the fact is 2 fields of that table together are unique in the table.how can i achieve the same using hibernate annotation?. here is my code.. @Entity @Table(name = "RolesMenuItems") public class RolesMenuItems { @Column(name = "RoleID") private String roleID; @Column(name = "MenuItemID") private String menuItemID; /*setter getter methods */ } 回答1: You can use

NHibernate Queryover - Is there any way of getting better SQL out of nHibernate when retrieving this object plus collections graph?

╄→гoц情女王★ 提交于 2019-12-25 08:48:42
问题 We have a situation where we are trying to retrieve a couple of levels deep for an object graph using QueryOver. So if our top level is ParentEntity and our children are ChildEntitysA, ChildEntitysB and ChildEntitysC then we have something like the following code to retrieve our graph. var query = session.QueryOver<ParentEntity>(() => pAlias).Where(() => pAlias.Id == key).Future<ParentEntity>(); var queryA = session.QueryOver<ParentEntity>(() => pAlias).Left.JoinAlias(x => x.ChildEntitysA, ()

Product with last 4 vendors on transaction date

瘦欲@ 提交于 2019-12-25 03:11:59
问题 Hi I have this sql and have to translate into NHibernate QueryOver SELECT S.Number, S.Description, S.BrandDescription, subquery.vendornumber, subquery.vendorname FROM Stocks.Stock S left join (select vendorNumber, VendorName, POLID, LastTransactionDate from ( SELECT top 4 v.Number vendorNumber, v.Name VendorName, PLL.Id POLID, max(por.TransactionDate) as LastTransactionDate, ROW_NUMBER() OVER(PARTITION BY v.Number ORDER BY max(por.TransactionDate) DESC) AS rk FROM Purchasing

Fill property of DTO with SubQuery in NHibernate Query

痞子三分冷 提交于 2019-12-25 02:55:10
问题 I have a DTO object like this: public class TreeViewDTO { public string Value { get; set; } public string Text { get; set; } public bool HasChildren { get; set; } } and my entity mapped with Nhibernate is: public class Entity { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual Entity Parent { get; set; } /* other properties */ } I would like to know, how can I get a List of my DTOs and fill the HasChildren property using a count method or a subquery

Nhibernate Queryover subquery and whereexists with 2 conditions

给你一囗甜甜゛ 提交于 2019-12-24 17:40:11
问题 Consider the following object structure. Product id : int name : string attribute : list of Attribute Attribute id : int name: string value : string product_id : int The questions is: Using QueryOver how to form a subquery to return all products with the following conditions: Select all products where when have attributes at the same time: Attribute name = "Color" Value="Red" and Attribute name = "Size" Value="XXL" ? Edit: Sample sql: select * from Product p where exists (select id from

nhibernate group by join query

强颜欢笑 提交于 2019-12-24 10:59:01
问题 I have the following entities: public class Shift { public virtual int ShiftId { get; set; } public virtual string ShiftDesc { get; set; } public virtual IList<ShiftHistory> ShiftHistory { get; set; } } public class ShiftHistory { public virtual System.DateTime ShiftStartLocal { get; set; } public virtual System.DateTime ShiftEndLocal { get; set; } public virtual Zone Zone { get; set; } public virtual Shift Shift { get; set; } public virtual int RowId { get; set; } } public class Zone {

NHibernate correlated subquery fetching single item

丶灬走出姿态 提交于 2019-12-24 09:35:59
问题 I'm using NHibernate 3.2 and have the following model: class User { public virtual int Id { get; set; } public virtual string Username { get; set; } public virtual IList<Log> Logs { get; set; } } class Log { public virtual int Id { get; set; } public virtual User User { get; set; } public virtual DateTime Date { get; set; } } Now, I want to query User with the date of ther latest Log-entry. class UserDto { public int UserId { get; set; } public string Username { get; set; } public DateTime?

NHibernate QueryOver - collection with too many results

六月ゝ 毕业季﹏ 提交于 2019-12-24 09:29:12
问题 Dear NHibernate users, I've been trying, reading and whatnot for 2 days now, but still can't figure this out, even though I presumed it to be an easy task with QueryOver API. These are my two entities: ATTRIBUTE --------------------------- public int Id { get; set; } public int LanguageId { get; set; } public string Title { get; set; } public IList<Option> Options { get; set; } OPTION --------------------------- public int Id { get; set; } public Attribute Attribute { get; set; } public int