Dynamic LINQ – Is There A .NET 4 Version?
You may want to take a look at PredicateBuilder
You may want to take a look at PredicateBuilder
Just use AutoMapper. Example: Mapper.CreateMap<Address, AddressDTO>(); Mapper.CreateMap<Person, PersonDTO>(); Your query will execute when the mapping is performed but if there are fields in the entity that you’re not interested use Project().To<> which is available both for NHibernate and EntityFramework. It will effectively do a select on the fields specified in the mapping configurations.
After investigation, it turns out things aren’t quite as bad as I thought. Basically, when everything is implemented properly (GetHashCode, etc.) the documentation is correct, and the behavior is correct. But, if you try to do something like implement IEquatable all by itself, then your Equals method will never get called (this seems to be … Read more
public string GetPath<T>(Expression<Func<T, object>> expr) { var stack = new Stack<string>(); MemberExpression me; switch (expr.Body.NodeType) { case ExpressionType.Convert: case ExpressionType.ConvertChecked: var ue = expr.Body as UnaryExpression; me = ((ue != null) ? ue.Operand : null) as MemberExpression; break; default: me = expr.Body as MemberExpression; break; } while (me != null) { stack.Push(me.Member.Name); me = me.Expression … Read more
private string MyMethod(int testParameter, Func<MyObject, string> selector) { return selector(_myObject); } When using Func delegates, the last parameter is the return type and the first N-1 are the argument types. In this case, there is a single MyObject argument to selector and it returns a string. You can invoke it like: string name = _myClassInstance.MyMethod(1, … Read more
Does LINQ have any native support for splitting a collection in 1 linear pass? There are no built-in methods that split a collection into two versions based on a predicate. You would need to use your own method, similar to the one you posted. The closest built-in method would be GroupBy (or ToLookup). You could … Read more
This is probably one of those rare cases where it makes sense to use an extern alias. In the properties page for the reference to System.Core (i.e. under References, select System.Core, right-click and select “Properties”), change the “Aliases” value to “global,SystemCore” (or just “SystemCore” if it’s blank to start with). Then in your code, write: … Read more
The @ symbol allows you to use a reserved keyword for a variable name. Such as @class. I’d assume Resharper does this to be safe. In this case, it is not needed and it doesn’t have any effect.
I’m assuming C#. DateTime startDate=bla; DateTime endDate=blabla; using(var db=new MyDataContext()) { var filteredData=db.TABLE.Where(t => t.DATE > startDate && t.DATE < endDate); //… }
Yes, they will be: GroupBy (MSDN). The IGrouping<TKey, TElement> objects are yielded in an order based on the order of the elements in source that produced the first key of each IGrouping<TKey, TElement>. Elements in a grouping are yielded in the order they appear in source.