.NET Core 2 – EF Core Error handling Save changes

Looking through the GitHub issues, there is no DbEntityValidationException equivalent in Entity Framework Core. There’s a blog post (linked from issue #9662 on GitHub), that gives a code example for performing the validation logic yourself, included here for completeness: class MyContext : DbContext { public override int SaveChanges() { var entities = from e in … Read more

Entity Framework Collection was modified; enumeration operation may not execute

You are seeing this because you delete objects from a collection that currently has active operations on. More specifically you are updating the Kids collection and then executing the Any() operator on it in the while loop. This is not a supported operation when working with IEnumerable instances. What I can advice you to do … Read more

Entity Framework Code First : how to annotate a foreign key for a “Default” value?

The problem is that when you have multiple relationships between two entities, EF Code First isn’t able to find out which navigation properties match up, unless, you tell it how, here is the code: public class Client { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } public string ClientName { get; set; } /****Change Nullable<int> … Read more

How to view database diagram in a Code First using localdb

Install Entity Framework Power Tools Beta 4, restart Visual Studio, right-click on the context in your solution view and you’ll see a new ‘Entity Framework’ option in the context menu. Select ‘View Entity Data Model’ to see a beautiful visual database diagram in Visual Studio. VoilĂ ! Entity Framework 6 Power Tools: Link

store only date in database not time portion C#

I think you are trying to specify database column type. You could use data annotations as described in this article. Here is an example : [Table(“People”)] public class Person { public int Id { get; set; } [Column(TypeName = “varchar”)] public string Name { get; set; } [Column(TypeName=”date”)] public DateTime DOB { get; set; } … Read more

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