ef-core-2.0

Is there a data annotation for unique constraint in EF Core (code first)?

佐手、 提交于 2019-11-27 16:44:03
问题 I am wondering if there is a data annotation for unique constraint in Entity Framework Core 2 code first approach? 回答1: In EF Core You could use the extension method HasAlternateKey in fluent API only. There are no data annotations to realize a unique constraint . This MS doc article - Alternate Keys (Unique Constraints) - will explain how to use and which further possibilities are exist. A short example from link above: class MyContext : DbContext { public DbSet<Car> Cars { get; set; }

Entity Framework Core is lazy loading when transforming

人盡茶涼 提交于 2019-11-27 08:19:59
问题 I'm having an issue with Entity Framework Core (v2.0.1) when transforming an entity model into a DTO. Basically it is, by any other version of the phrase, lazy loading when I don't want it to. Here's a simple .NET Core Console application (with the Microsoft.EntityFrameworkCore.SqlServer (2.0.1) package). using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq;

Cascade deleting with EF Core

百般思念 提交于 2019-11-26 20:14:45
问题 I am having a few issues with EF Core at the moment. I have some data that I need to delete, and I am struggeling to see how the fluent API works, exactly in regards to the .OnDelete() function. Considering the classic blog/post scenario from microsofts own websites, I wonder what entity, exactly the OnDelete() is 'targeting' (for the lack of a better word) In some instances it seems to be the blog, in others, the post. Can the Cascade delete be defined from both sides (that the posts are