NHibernate 3.0: No FirstOrDefault() with QueryOver?

I have now found out that I could use the Take() extension method on the IQueryOver instance, and only the enumerate to a list, like so: Result precedingOrMatchingResult = Session.QueryOver<Result>(). Where(r => r.TimeStamp < timeStamp). OrderBy(r => r.TimeStamp).Desc. Take(1).List(). //enumerate only on element of the sequence! FirstOrDefault(); //get the preceding or matching result, if there … Read more

Eagerly fetch multiple collection properties (using QueryOver/Linq)?

I prefer to use the linq provider if at all possible especially if you are using newer versions of nhibernate (>= 4.0). As long as you have your collections mapped as ISets (requires .net framework >= 4) which we converted to such that we could do eager loading and avoid cartesian products. I feel like … Read more

Convert anonymous type to new C# 7 tuple type

Of course, by creating the tuple from your LINQ expression: public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => (o.Id,o.Name)) .First(); return obj; } According to another answer regarding pre-C# 7 tuples, you can use AsEnumerable() to prevent EF to mix things up. (I have not much experience with EF, but … Read more

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

In the TearDown of my UnitTests, I mostly do this: using( ISession s = … ) { s.Delete (“from Object o”); s.Flush(); } This should delete all entities. If you want to delete all instances of one specific entity, you can do this: using( ISession s = …. ) { s.Delete (“from MyEntityName e”); s.Flush(); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)