Using DateTime properties in Code-First Entity Framework and SQL Server

You can specify the type in Fluent API: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”); This creates a datetime2(7) column in the database. If you want to finetune the precision you can use: modelBuilder.Entity<Book>() .Property(f => f.DateTimeAdded) .HasColumnType(“datetime2”) .HasPrecision(0); … for a datetime2(0) column in the DB. However, the code you have shown in your question works … Read more

Entity Framework migrations stopped detecting the POCO updates

This may be in two reasons: There is some other DbContext in code, that’s why automatic migrations could not decide, which context to use. There is some new change, which loops a comparison of schema and code model, so EF simply could not find the difference. In general, automatic migrations are simple and fast to … Read more

Why is ON DELETE SET NULL still not implemented in the Entity Framework 6? Is there a snag?

The feature is probably not implemented because normally changes only affect the objects which are actually in the unit of work. Cascades are not scalable. And I also think soft deletes are better in most cases. Maybe thats something for you? You might also want to look into Domain Driven design. That also covers the … Read more

SQLite Error 14: ‘unable to open database file’ with EF Core code first

i think the issue is that the EntityFramework Core can’t create folders by itself while using SQLite provider. Don’t know if the issue also appears when using other filebased database providers. i had the same issue: my datasource was something like: optionsBuilder.UseSqlite(@”Data Source=c:\foo_db\bar_db.db”); after i created the “foo_db” folder inside the c:\ drive, the problem … Read more

Entity Framework Not Creating Database

Asked around on the MSDN forums instead, and got a satisfactory answer: Entity Framework will not create a database until first access. The current code block in Application_Start() only specifies the strategy to use when creating the database during first access. To trigger creation of the database on startup, an instance of the database context … Read more

Enums with EF code-first – standard method to seeding DB and then using?

Unfortunately, enums are not natively supported on EF 4.1. Here’s one rather known article on how to deal with them: Faking enums on EF 4. It does, however, require a wrapper. There’s a simpler way to map enums in EF 4 however: just create an int property on your class to represent the int value … 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

Why does Entity Framework return null List instead of empty ones?

You should have your entity create those lists in the constructor. EF doesn’t create dependent collections, and expects the entity to do so. So, your case, you would make your entity like this: class MyClass{ public List<OtherClass> _otherClasses {get;set;} public MyClass() { _otherClasses = new List<OtherClass>(); } }

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