linq-to-nhibernate

Nhibernate .Fetch calls fail on a mocked session

徘徊边缘 提交于 2019-12-04 04:31:26
I love NHibernate (and NHibernate.Linq). I don't prematurely optimize, but sometimes I'll hit a really nasty N+1 issue. The recommended fix for the N+1 is to use NH's Fetch extension method. The problem arises when I create a Mock of the ISession . I'll create a List<User> and set my mock to return the list whenever someone calls _session.Query<User>() . When I add a Fetch call to the query (i.e. _session.Query<User>().Fetch(u => u.Address) , I get the following error message: There is no method 'Fetch' on type 'NHibernate.Linq.EagerFetchingExtensionMethods' that matches the specified

Conditional operator in Linq Expression causes NHibernate exception

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 03:16:53
问题 I'm trying to implement search functionality in an ASP.NET MVC 2 application. I create an expression based on criteria entered by the user: public ViewResult FindCustomer( string forename, string familyname, DateTime? dob) { Expression<Func<Customer, bool>> searchCriteria = p => ( forename.IsNullOrEmpty() ? true : p.Forename == forename && familyname.IsNullOrEmpty() ? true : p.FamilyNames.Any(n => n.Name == familyname) && dob.HasValue ? true : p.DOB == dob ); which then gets passed to a

Best way to delete all rows in a table using NHibernate?

拜拜、爱过 提交于 2019-12-03 18:30:02
问题 To keep my integration tests independent I remove all old data and insert new test data before each test. Is there a better way of doing this than simply querying for all entities and deleting them one by one? I have considered writing a stored proc that runs "delete from tablename ;" for each table that is to be cleared. That ought to quite a bit faster, but it would be nice to do it without doing SQL queries or calling SPs via NH. I'm using vanilla NHibernate and Linq to NHibernate. I

NHibernate - Where ISession.Query<T>() is located

五迷三道 提交于 2019-12-03 16:03:11
问题 When I try to compile the following code using System; using System.Collections.Generic; using System.Reflection; using System.Linq; using NHibernate; namespace NewNHTest { class A { } class Program { static void Main(string[] args) { ISession session; var q = session.Query<A>(); } } } I get the following error: 'NHibernate.ISession' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'NHibernate.ISession' could be found (are you

NHibernate.Linq LIKE

夙愿已清 提交于 2019-12-03 09:43:57
How can I produce this query using NHibernate.Linq? WHERE this_.Name LIKE @p0; @p0 = 'test' // Notice NO % wild card Note, this is not Linq To Sql or Entity Framework. This is NHibernate. Edit: Here is the desired query using ICriteria: criteria.Add(Expression.Like("Name", "test")); return criteria.List<Theater>(); With NH 4 (and probably a bit earlier), a built-in Like string extension is available within NHibernate.Linq namespace: Like(this string matchExpression, string sqlLikePattern) . (It is defined on NHibernate.Linq.SqlMethods extension class.) using NHibernate.Linq; ... session.Query

NHibernate 3. Alternatives to “ThenFetch” in QueryOver

ε祈祈猫儿з 提交于 2019-12-03 09:13:04
问题 I'm using NHibernate 3.0 with both the LINQ provider and QueryOver. Sometimes I want to eager load related data, and there comes the method "Fetch" to the rescue, both in LINQ and QueryOver. Now I have a special scenario where I want to eager load a property not directly on the second level, like: Foo f = ...; f.A.B.C with LINQ there's no problem, as you can "chain" fetches with the method "ThenFetch", like: var result = Session.Query<Foo>().Fetch(a => a.A).ThenFetch(b => b.B).ThenFetch(c =>

NHibernate.Linq and MultiCriteria

大兔子大兔子 提交于 2019-12-03 05:55:15
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 nice if I replace the CreateCriteria calls with Linq calls and get something like this: var crit =

NHibernate - Where ISession.Query<T>() is located

你离开我真会死。 提交于 2019-12-03 04:32:58
When I try to compile the following code using System; using System.Collections.Generic; using System.Reflection; using System.Linq; using NHibernate; namespace NewNHTest { class A { } class Program { static void Main(string[] args) { ISession session; var q = session.Query<A>(); } } } I get the following error: 'NHibernate.ISession' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'NHibernate.ISession' could be found (are you missing a using directive or an assembly reference?) NHibernate.dll version is 3.0.0.4000. The .Net version

Problem with linq query

混江龙づ霸主 提交于 2019-12-03 04:20:22
I'm trying to use linq to NHibernate (with Fluent NHibernate) but I have problems with linq query. Everytime I try to execute it I get this message : " Method 'get_IsReadOnlyInitialized' in type 'NHibernate.Linq.Util.DetachedCriteriaAdapter' from assembly 'NHibernate.Linq, Version=1.1.0.1001, Culture=neutral, PublicKeyToken=null' does not have an implementation. " Does anybody know how to fix this problem? I tried with solution form this page with model context but it didn't help. This is the code: using(var session = NHibernateHelper.OpenSession()) { var informations = (from i in session

NHibernate 3. Alternatives to “ThenFetch” in QueryOver

ぐ巨炮叔叔 提交于 2019-12-02 23:24:15
I'm using NHibernate 3.0 with both the LINQ provider and QueryOver. Sometimes I want to eager load related data, and there comes the method "Fetch" to the rescue, both in LINQ and QueryOver. Now I have a special scenario where I want to eager load a property not directly on the second level, like: Foo f = ...; f.A.B.C with LINQ there's no problem, as you can "chain" fetches with the method "ThenFetch", like: var result = Session.Query<Foo>().Fetch(a => a.A).ThenFetch(b => b.B).ThenFetch(c => c.C).ToList(); In QueryOver there's no such method, so how can I achieve the same result? Thanks in