linq-to-nhibernate

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?

The method or operation is not implemented while using linq to nhibernate

随声附和 提交于 2019-12-24 00:58:08
问题 i m trying to use linq to nhibernate 3 and i have made following linq query var a = (from c in Session.Query<ChoiceValue>() join Specific in ( (from choicevaluelocale in Session.Query<ChoiceValueLocale>() where choicevaluelocale.UICulture == "en-GB" select new { choicevaluelocale.ChoiceValue.ChoiceGroup.ChoiceGroupName, choicevaluelocale.ChoiceValue.ChoiceValueId, choicevaluelocale.DisplayName, choicevaluelocale.Description })) on new { c.ChoiceGroup.ChoiceGroupName, c.ChoiceValueId } equals

LINQ-NHibernate - Selecting only a few fields (including a Collection) for a complex object

坚强是说给别人听的谎言 提交于 2019-12-23 12:20:57
问题 I'm using Fluent NHibernate in one of my projects (and ASP.NET MVC application), with LINQ to query to data (using the LINQ to NHibernate libraries). The objet names are changed to protect the innocent. Let's say I have the following classes Foo, Bar, Baz, and their appropriate tables in the database (MySQL). Foo has a many-to-many relationship with both Bar (table "FooBar") and Baz (table "FooBaz"), defined in the Fluent mappings. As such, the class interface is defined as follows: public

In Linq-to-Nhibernate, is it possible to use .Fetch() after a .Select()?

人走茶凉 提交于 2019-12-23 03:01:12
问题 If I had an Object A that contained a many-to-one reference to Object B, where Object B contained a one-to-many collection of Object C... consider the following query: IQueryable<A> query = getIQueryableSomehow(); List<B> resultList = query.Where(A => A.whatever == something).Select(A => A.B).Fetch(B => B.C).ToList(); I want to do something similar to this, but I keep getting a null reference exception with this code. Is there a sneaky trick to achieve this kind of query AND fetch a bunch of

Adding calculated properties to class throws NHibernate error when using Linq to NHibernate

大憨熊 提交于 2019-12-22 10:35:40
问题 I added some calculated read-only properties to my class and it's now throwing a QueryException: could not resolve property. Here is my class (fake calculations right now): public class IncompleteApplication : DealerBase { public virtual string Content { get; set; } public virtual string LegalBusinessName { get { return "Leg"; } } public virtual string DbaName { get { return "Dba"; } } } Mapping: public class IncompleteApplicationMap : DealerBaseMap<IncompleteApplication> { public

Good behaviour for eager loading multiple siblings and grandchildren (cousins?) in NHibernate 3.0 Linq

前提是你 提交于 2019-12-22 09:05:36
问题 I'm trying to do the following with NHibernate 3.0's LINQ interface. I want to query for an object (using some Where clause), and load some children and grandchildren. Currently I'm doing it like so: var results = session.Query<Thing>() .Where(...) .Fetch(x => x.SubThingA) .ThenFetch(st => st.SubSubThingA) .Fetch(x => x.SubThingB) .ThenFetch(st => st.SubSubThingB) // etc... However, this results in a Cartesian product between all grandchildren (every result row contains many, many columns).

'string' does not contain a definition for 'Contains'

隐身守侯 提交于 2019-12-22 04:08:16
问题 I have a statement like so: var vals = from StandAloneUserPayment saup in _Session.Query<StandAloneUserPayment>() .Fetch(x => x.RecurringPayments) where saup.User.UserId == userId && searchString.Contains(saup.FriendlyName, StringComparer.InvariantCultureIgnoreCase) select saup; This seems to be exactly what I'm supposed to do, but I get the whole line with the Contains method underlined with the following message: string does not contain a definition for Contains and the best extension

Nhibernate Linq In Clause

二次信任 提交于 2019-12-22 02:00:08
问题 Is it possible to get Nhibernate linq to generate a query with an "In" clause? e.g. - Where AnID in (x,y,z) ? 回答1: I don't know the state of nHibernate with respect to generating all the potential LINQ queries, but you should be able to use .Contains() to generate an IN. var list = new int[] { x, y, x }; var q = db.Entities.Where( e => list.Contains( e.AnID ) ); 回答2: Agreed, this does work. I found the generated SQL for 'not in' to be strange though (as of 3.3.0 GA) ... from mytable t0_ where

Linq Nhibernate left join

不羁的心 提交于 2019-12-20 07:52:28
问题 A Theft has an action property This is the query i'm trying to get NHibernate.Linq to produce: SELECT * FROM `thefts` LEFT JOIN memberThefts ON thefts.id = memberThefts.theftId AND memberThefts.memberId = 1 I want to get a list of all the thefts where action.memberId == some number or just null if it doesn't find a row, simple as a query yet it's been giving me a nightmare all day! thefts = session.Query<Theft>() .Fetch(x => x.action) .Where(x => x.action.memberId == member.id) .ToList();

How to compare just the date, not the timestamp using LINQ

我与影子孤独终老i 提交于 2019-12-20 06:32:12
问题 I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back. How could I write this same LINQ query if I'm only interested in the actual date value matching? The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00 from t in UnitsOfWork _ where t.ImportDate = "08/30/2009" _ select t 回答1: You can compare it as a string or you can use just the Date property on ImportDate where t.ImportDate.ToString(