How to compare only date components from DateTime in EF?

Use the class EntityFunctions for trimming the time portion. using System.Data.Objects; var bla = (from log in context.Contacts where EntityFunctions.TruncateTime(log.ModifiedDate) == EntityFunctions.TruncateTime(today.Date) select log).FirstOrDefault(); Source: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/84d4e18b-7545-419b-9826-53ff1a0e2a62/ UPDATE As of EF 6.0 and later EntityFunctions is replaced by DbFunctions.

Entity Framework – Add Navigation Property Manually

Yup – it’s not that straightforward. Here’s what you do: 1 – Right click on the designer, Add -> Association 2 – Setup the association and cardinalities (People *..1 Gender, People *..1 Race) 3 – Go into the Model Browser -> Associations 4 – Right click on your newly created associations, click Properties 5 – … Read more

‘No database provider has been configured for this DbContext’ on SignInManager.PasswordSignInAsync

If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext. The error message says your DbContext(LogManagerContext ) needs a constructor which accepts a DbContextOptions. But I couldn’t find such a constructor in your DbContext. So adding the below … Read more

Entity Framework Queryable async

The problem seems to be that you have misunderstood how async/await work with Entity Framework. About Entity Framework So, let’s look at this code: public IQueryable<URL> GetAllUrls() { return context.Urls.AsQueryable(); } and example of it usage: repo.GetAllUrls().Where(u => <condition>).Take(10).ToList() What happens there? We are getting IQueryable object (not accessing database yet) using repo.GetAllUrls() We create … Read more

It has a DefiningQuery but no InsertFunction element… err

Well when a table is encountered without a PrimaryKey it is treated as a View. And views show up in the EDMX file (open in an XML editor to see) in the StorageModel\EntitySet[n]\DefiningQuery element. When you have a DefiningQuery the Entity becomes readonly unless you add modification functions. You need 3 modifications functions (aka Stored … Read more

Create a Tuple in a Linq Select

While the answer by octavioccl works, it’s better to first project the query result into anonymous type, and then switch to enumerable and convert it to tuple. This way your query will retrieve from the data base only the fields needed. codes = codesRepo.SearchFor(predicate) .Select(c => new { c.Id, c.Flag }) .AsEnumerable() .Select(c => new … Read more

EF Code First foreign key without navigation property

Although this post is for Entity Framework not Entity Framework Core, It might be useful for someone who wants to achieve the same thing using Entity Framework Core (I am using V1.1.2). I don’t need navigation properties (although they’re nice) because I am practicing DDD and I want Parent and Child to be two separate … Read more