linq-to-nhibernate

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

旧时模样 提交于 2019-12-05 20:45:54
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 IncompleteApplicationMap() { Schema("Dealer"); Table("XmlSerialization"); Map(app => app.Content); } } And calling

NHibernate Linq Query with Projection and Count error

一笑奈何 提交于 2019-12-05 16:14:01
I have the following query: var list = repositoy.Query<MyClass>.Select(domain => new MyDto() { Id = domain.Id, StringComma = string.Join(",", domain.MyList.Select(y => y.Name)) }); That works great: list.ToList(); But if I try to get the Count I got an exception: list.Count(); Exception NHibernate.Hql.Ast.ANTLR.QuerySyntaxException A recognition error occurred. [.Count[MyDto](.Select[MyClass,MyDto](NHibernate.Linq.NhQueryable`1[MyClass], Quote((domain, ) => (new MyDto()domain.Iddomain.Name.Join(p1, .Select[MyListClass,System.String](domain.MyList, (y, ) => (y.Name), ), ))), ), )] Any idea how

Is this the right way of using ThenFetch() to load multiple collections?

人走茶凉 提交于 2019-12-05 03:27:14
I'm trying to load all the collections eagerly, using NHibernate 3 alpha 1 . I'm wondering if this the right way of using ThenFetch()? Properties with plural names are collections. The others are just a single object. IQueryable<T> milestoneInstances = Db.Find<T, IQueryable<T>>(db => from mi in db where mi.RunDate == runDate select mi).Fetch(mi => mi.Milestone) .ThenFetch(m => m.PrimaryOwners) .Fetch(mi => mi.Milestone) .ThenFetch(m => m.SecondaryOwners) .Fetch(mi => mi.Milestone) .ThenFetch(m => m.Predecessors) .Fetch(mi => mi.Milestone) .ThenFetch(m => m.Function) .Fetch(mi => mi.Milestone)

Nhibernate Linq In Clause

余生长醉 提交于 2019-12-04 23:51:10
Is it possible to get Nhibernate linq to generate a query with an "In" clause? e.g. - Where AnID in (x,y,z) ? 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 ) ); 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 case when t0_.testValue in ( @p0 , @p1 , @p2 ) then 1 else 0 end=@p3 @p0 = 9 [Type: Int32 (0)], @p1 = 99 [Type:

Convert anonymous type to new C# 7 tuple type

放肆的年华 提交于 2019-12-04 22:17:01
The new version of C# is there, with the useful new feature Tuple Types: public IQueryable<T> Query<T>(); public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => new { id = o.Id, name = o.Name, }) .First(); return (id: obj.id, name: obj.name); } Is there a way to convert my anonymous type object obj to the tuple that I want to return without mapping property by property (assuming that the names of the properties match)? The context is in a ORM, my SomeType object has a lot of other properties and it is mapped to a table with lot of columns. I wanna do a query that

Can NHibernate query for specific children without lazy loading the entire collection?

久未见 提交于 2019-12-04 16:17:08
When I have an entity object with a one-to-many child collection, and I need to query for a specific child object, is there a feature or some clever pattern I haven't come up with yet to avoid that NHibernate fetches the entire child collection? Example: class Parent { public virtual int Id { get; proteced set; } // generated PK public virtual IEnumerable<Child> Children { get; proteced set; } } class Child { public virtual int Id { get; protected set; } // generated PK public virtual string Name { get; protected set; } public virtual Parent Parent { get; protected set; } } // mapped with

Latest Binary builds of FLuentNhibernate + Nhibernate + Linq for NHibernate

荒凉一梦 提交于 2019-12-04 11:36:05
do people build there own versions of all this? or is there a place to get all this prebuilt? I got the latest FluentNhibernate which has NHibernate but no Linq.... but I don't really want to setup a ruby rake build system etc etc unless I really really have to! Prefer to just get all the binaries I need. Here is a build: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and-fluent.html I build my own versions, because I don't want to be forced to upgrade all the dependencies of fluent when I just want to upgrade fluentnhibernate. Installing ruby is downloading and clicking one

Linq to NHibernate extensibility for custom string query operations?

人走茶凉 提交于 2019-12-04 11:05:10
I would like to be able to use custom string querying within my NHibernate Linq expressions. Let's say for example (and this is just an example) I would like to be able to select entities containing a property which is an anagram of a particular string: var myEntities = EntityRepository.AllEntities.Where(x => x.Description.IsAnagramOf('hits'); I imagine the steps involved in this process would be: Define a SQL Server UDF to determine whether two strings are anagrams. Define an extension method called IsAnagramOf() for the String class. (And this is the tricky one). Modify Linq to NHibernate's

NHibernate.Linq and MultiCriteria

馋奶兔 提交于 2019-12-04 10:40:27
问题 Anybody know of a way to batch NHibernate queries using NHibernate.Linq like you can do with MultiCriteria and ICriteria objects? With MultiCriteria I can create something like this: var crit = session.CreateMultiCriteria() .Add(session.CreateCriteria(typeof(Entity1)).Add(Restrictions.Eq("Property1","Value")) .Add(session.CreateCriteria(typeof(Entity2)).Add(Restrictions.Eq("Property2","Value2")); var result = crit.List(); var list1 = (IList)result[0]; var list2 = (IList)result[1]; It would be

Eager loading child and child-of-child collections in NHibernate

一个人想着一个人 提交于 2019-12-04 09:04:14
I've got a problem with NHibernate trying to load a small hierarchy of data. My domain model looks like: class GrandParent { int ID{get;set;} IList<Parent> Parents {get; set;} } class Parent { IList<Child> Children {get; set;} } class Child { } and I would like to eager load all parents and children for a given GrandParent. This Linq-to-NH query creates the correct SQL and loads the GrandParent as expected: (the example assumes the grandparent has 2 parents who each have 2 child objects - so 4 child objects in total). var linq = session.Linq<GrandParent>(); linq.Expand("Parents"); linq.Expand(