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

IEqualityComparer for anonymous type

The trick is to create a comparer that only works on inferred types. For instance: public class Comparer<T> : IComparer<T> { private Func<T,T,int> _func; public Comparer(Func<T,T,int> func) { _func = func; } public int Compare(T x, T y ) { return _func(x,y); } } public static class Comparer { public static Comparer<T> Create<T>(Func<T,T,int> func){ return … Read more

Simple Examples of joining 2 and 3 table using lambda expression

Code for joining 3 tables is: var list = dc.Orders. Join(dc.Order_Details, o => o.OrderID, od => od.OrderID, (o, od) => new { OrderID = o.OrderID, OrderDate = o.OrderDate, ShipName = o.ShipName, Quantity = od.Quantity, UnitPrice = od.UnitPrice, ProductID = od.ProductID }).Join(dc.Products, a => a.ProductID, p => p.ProductID, (a, p) => new { OrderID = a.OrderID, … Read more

Is there a “not equal” in a linq join

You don’t need a join for that: var filteredEmployees = groupA.Except(groupB); Note that this will be a sequence of unique employees – so if there are any duplicates in groupA, they will only appear once in filteredEmployees. Of course, it also assumes you’ve got a reasonable equality comparer1. If you need to go specifically on … Read more

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