Cleanest Way To Map Entity To DTO With Linq Select?

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.

Creating a common predicate function

The neat thing about how LINQ to SQL handles expressions is that you can actually build out expressions elsewhere in your code and reference them in your queries. Why don’t you try something like this: public static class Predicates { public static Expression<Func<User, bool>> CheckForFlags() { return (user => user.Flag1 || user.Flag2 || user.Flag3 || … Read more

DISTINCT() and ORDERBY issue

From the Queryable.Distinct documentation; The expected behavior is that it returns an unordered sequence of the unique items in source. In other words, any order the existing IQueryable has is lost when you use Distinct() on it. What you want is probably something more like this, an OrderBy() after the Distinct() is done; var query … Read more

Can I stop the dbml designer from adding a connection string to the dbml file? [duplicate]

While in the designer for the DBML, you can right-click on any white-space, and click on Properties (not the same as right-clicking on the DBML file and clicking Properties). From there, expand the “Connection” option. Set “Application Settings” to False and clear out the “Connection String” setting. These settings are what the designer uses to … Read more