linq to entities vs linq to objects – are they the same?

That is definitely not the case. LINQ-to-Objects is a set of extension methods on IEnumerable<T> that allow you to perform in-memory query operations on arbitrary sequences of objects. The methods accept simple delegates when necessary. LINQ-to-Entities is a LINQ provider that has a set of extension methods on IQueryable<T>. The methods build up an expression … Read more

The right way to insert multiple records to a table using LINQ to Entities

Simply move the instantiation of the new Product inside the loop. Your code as it is written will add a single instance multiple times which does not produce what you are after…you need a separate instance of each product…the Add method does not make a copy, it attaches the object to the context and marks … Read more

LINQ to Entities does not recognize the method ‘System.DateTime GetValueOrDefault()’

You should be able to use the Null Coalescing operator ??: addresses = (from a in db.ADDRESS where a.CUSTOMER_NUMBER.Equals(customer_number) select new AddressModel { Address_Id = a.ADDRESS_ID, System_Id = a.SYSTEM_ID, Customer_Number = a.CUSTOMER_NUMBER, Address_Type = a.ADDRESS_TYPE, Changed_On = a.CHANGED_ON ?? DateTime.MinValue, Created_On = a.CREATED_ON ?? DateTime.MinValue, Email = a.EMAIL }).ToList();

Can’t get EntityFunctions.TruncateTime() to work

I faced this problem recently when I upgraded my Web Application from Entity Framework 5 to Entity Framework 6. Then, I realized that System.Data.Entity DLL needs to be removed from the application completely in order to work with Entity Framework 6. Entity Framework 6 is not part of .NET Framework anymore and therefore it is … Read more

Linq when using GroupBy, Include is not working

Include demands that the shape of the query doesn’t change. It means that your query must return IQueryable<Match>. GroupBy operator is probably considered as shape changing because it returns IQueryable<IGrouping<TKey, TSource>>. Once the shape of the query changes all Include statements are omitted. Because of that you cannot use Include with projections, custom joins and … Read more

Simple Automapper Example

1- Change the GroupDto to be like this: [DataContract] public class GroupDto { [DataMember] public int id { get; set; } [DataMember] public string name{ get; set; } [DataMember] public List<UserDTO> Users { get; set; } } 2- Create your mappings : Mapper.CreateMap<User, UserDto>(); Mapper.CreateMap<UserDto, User>(); // Only if you convert back from dto to … Read more

How to tell if an IEnumerable is subject to deferred execution?

Deferred execution of LINQ has trapped a lot of people, you’re not alone. The approach I’ve taken to avoiding this problem is as follows: Parameters to methods – use IEnumerable<T> unless there’s a need for a more specific interface. Local variables – usually at the point where I create the LINQ, so I’ll know whether … Read more

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