get date part only from datetime value using entity framework

You can compare just specified parts: context.tblvalue.Any(x => x.date.Year == data.Year && x.date.Month == data.Month && x.date.Day == data.Day); EDIT: You can also try the following: context.tblvalue.Any(x => EntityFunctions.TruncateTime(x.date) == data.Date); Another approach: context.tblvalue.Any(x => SqlFunctions.DatePart(“year”, x.date) == data.Year && SqlFunctions.DatePart(“month”, x.date) == data.Month && SqlFunctions.DatePart(“day”, x.date) == data.Day);

Modelling polymorphic associations database-first vs code-first

I personally stick with Database first when using EF on any schema that is this level of complexity. I have had issues with complex schemas in regards to code first. Maybe the newer versions are a little better, but worrying how to try and code complex relationships seems less straight forward then allowing the engine … Read more

Can EF automatically delete data that is orphaned, where the parent is not deleted?

It is actually supported but only when you use Identifying relation. It works with code first as well. You just need to define complex key for your ChildObject containing both Id and ParentObjectId: modelBuilder.Entity<ChildObject>() .HasKey(c => new {c.Id, c.ParentObjectId}); Because defining such key will remove default convention for auto incremented Id you must redefine it … Read more

EF5 Getting this error message: Model compatibility cannot be checked because the database does not contain model metadata

I found the code working by changing static LaundryShopContext() { Database.SetInitializer<LaundryShopContext>( new DropCreateDatabaseIfModelChanges<LaundryShopContext>()); } into static LaundryShopContext() { Database.SetInitializer<LaundryShopContext>( new DropCreateDatabaseAlways<LaundryShopContext>()); }

EF migration for changing data type of columns

You have a default constraint on your column. You need to first drop the constraint, then alter your column. public override void Up() { Sql(“ALTER TABLE dbo.Received DROP CONSTRAINT DF_Receiv_FromN__25869641”); AlterColumn(“dbo.Received”, “FromNo”, c => c.String()); AlterColumn(“dbo.Received”, “ToNo”, c => c.String()); AlterColumn(“dbo.Received”, “TicketNo”, c => c.String()); } You will probably have to drop the default constraints … Read more

Mapping Database Views to EF 5.0 Code First w/Migrations

You have specified that the ClientStatisticsView entity should be mapped to a table named “ClientStatistics”. So entity framework will generate a migration containing an instruction to create that table. But you have independently created that view in the database so to prevent the error you are getting you should remove the CreateTable instruction from the … Read more

Use Entity framework I want to include only first children objects and not child of child(sub of sub)

I now see that a big part of the original answer is nonsense. Sure enough, the reason for the endless loop is relationship fixup. But you can’t stop EF from doing that. Even when using AsNoTracking, EF performs relationship fixup in the objects that are materialized in one query. Thus, your query with Include will … Read more