ef-fluent-api

Defining Self Referencing Foreign-Key-Relationship Using Entity Framework 7 Code First

Deadly 提交于 2021-02-07 09:00:20
问题 I have an ArticleComment entity as you can see below: public class ArticleComment { public int ArticleCommentId { get; set; } public int? ArticleCommentParentId { get; set; } //[ForeignKey("ArticleCommentParentId")] public virtual ArticleComment Comment { get; set; } public DateTime ArticleDateCreated { get; set; } public string ArticleCommentName { get; set; } public string ArticleCommentEmail { get; set; } public string ArticleCommentWebSite { get; set; } public string AricleCommentBody {

Setting up a relationship in Entity Framework Core

China☆狼群 提交于 2021-01-29 09:55:04
问题 I'm trying to set up a one to many relationship in Entity Framework Core using the Fluent API with no success. I have two objects called Message and Source and are defined as public class Message { public int ID { get; set; } public int FromUserID { get; set; } public int ToUserID { get; set; } public int SourceID { get; set; } public int Priority { get; set; } public string Subject { get; set; } public string MessageBody { get; set; } public DateTime DateTimeCreated { get; set; } public

Mapping inheritance in EntityFramework Core

孤者浪人 提交于 2021-01-27 21:10:22
问题 I'm using EntityFramework Core, Code First and Fluent Api to define model database, and i've follow situation about strategy of map inheritance: public class Person { public int Id { get; set; } public string Name { get; set; } } public class User : Person { public string UserName { get; set; } public string Password { get; set; } } public class Employee : Person { public decimal Salary { get; set; } } public class Customer:Person { public long DiscountPoints { get; set; } } Business logical

Entity Framework 6 creates Id column even though other primary key is defined

守給你的承諾、 提交于 2021-01-27 05:31:16
问题 I defined a DataObject as: public class SensorType : EntityData { //PKs public string CompanyId { get; set; } public string ServiceId { get; set; } public string Type { get; set; } } And used fluent API to make CompanyId and ServiceId a composite key: modelBuilder.Entity<SensorType>() .HasKey(t => new { t.CompanyId, t.ServiceId }); //No autogeneration of PKs modelBuilder.Entity<SensorType>().Property(t => t.ServiceId) .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema

Entity Framework 6 creates Id column even though other primary key is defined

ぐ巨炮叔叔 提交于 2021-01-27 05:30:42
问题 I defined a DataObject as: public class SensorType : EntityData { //PKs public string CompanyId { get; set; } public string ServiceId { get; set; } public string Type { get; set; } } And used fluent API to make CompanyId and ServiceId a composite key: modelBuilder.Entity<SensorType>() .HasKey(t => new { t.CompanyId, t.ServiceId }); //No autogeneration of PKs modelBuilder.Entity<SensorType>().Property(t => t.ServiceId) .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema

Does the EF Fluent Api can setting the Minimum Length?

时光毁灭记忆、已成空白 提交于 2020-06-27 08:23:25
问题 It seems use the Fluent API has more flexibility. So I choose the way to follow always use the Fluent API to determine the feature it have in db instead use the annotations to. But here is the problem,I couldn't find the way to set the Minimum length. Is there a method to perform this? And i notice,there are no much topic discuss this way.Is the Fluent API way popular?? Hope we choose the right side. 回答1: This is impossible at the moment with EF. If you really have to set a minimum length,

EF can you make a Mutli-column Index using shadow properties?

╄→гoц情女王★ 提交于 2020-05-23 12:24:06
问题 I'm trying to create a multi-column unique index using a shadow property. I know I can solve this problem with just adding a property, but I would like to see if this is possible in a way to keep my model clean. To create a multi-column index you have the following option in Fluent API: modelBuilder.Entity<AlbumTrack>().HasIndex(t => new { t.TrackNumber, t.AlbumId).IsUnique(); But I don't want to clutter my model with an extra AlbumId property and thus would like to use a shadow property, for

Use IEntityTypeConfiguration with a base entity

╄→гoц情女王★ 提交于 2020-04-07 19:07:50
问题 In EF Core 2.0, we have the ability to derive from IEntityTypeConfiguration for cleaner Fluent API mappings (source). How can I extend this pattern to utilize a base entity? In the example below, how can I have a BaseEntityConfiguration to reduce duplication in LanguageConfiguration and MaintainerConfiguration , modifying properties that are in the BaseEntity only in the BaseEntityConfiguration ? What would such a BaseEntityConfiguration look like; and how would it be used, if at all, in