table-per-type

How to implement inheritance Table-Per-Type in Entity Framework 4.3 via Code First approach?

大城市里の小女人 提交于 2019-12-01 08:33:18
问题 I have this class hierarchy in code: [Table("A")] public class A : IIdentification { public int id { get; set; } } [Table("B")] public class B : A { //some properties here public Aid { get; set;} ForeignKey("Aid"); public A A { get; set; } } [Table("C")] public class C : B { //some properties here public Bid { get; set; } ForeignKey("Bid"); public B B { get; set; } } [Table("D")] public class D : C { public Cid { get; set;} ForeignKey("Cid"); public C C { get; set; } } How can I make one

Converting a EF CodeFirst Base class to a Inherited class (using table-per-type)

萝らか妹 提交于 2019-11-30 15:11:14
I am using EF Code First and have two classes defined as follows: public class User { public int Id { get; set; } public string Username { get; set; } public string Email { get; set; } } [Table("Visitors")] public class Visitor : User { public Visitor() { Favourites = new List<Building>(); } public virtual IList<Building> Favourites { get; set; } } This uses Table-Per-Type inheritance and defines the DB schema as follows: Users Table Id int PK Username nvarchar(max) Email nvarchar(max) Visitors Table Id int PK (FK to Users table) This is exactly how I wanted it to structure it. Now my question

Converting a EF CodeFirst Base class to a Inherited class (using table-per-type)

允我心安 提交于 2019-11-29 21:45:39
问题 I am using EF Code First and have two classes defined as follows: public class User { public int Id { get; set; } public string Username { get; set; } public string Email { get; set; } } [Table("Visitors")] public class Visitor : User { public Visitor() { Favourites = new List<Building>(); } public virtual IList<Building> Favourites { get; set; } } This uses Table-Per-Type inheritance and defines the DB schema as follows: Users Table Id int PK Username nvarchar(max) Email nvarchar(max)

Inheritance and composite foreign keys - one part of the key in base class, the other part in derived class

為{幸葍}努か 提交于 2019-11-28 11:56:24
I am having problems to create an Entity Framework Code-First mapping for the following sample database schema (in SQL Server): Every table contains a TenantId which is part of all (composite) primary and foreign keys (Multi-Tenancy). A Company is either a Customer or a Supplier and I try to model this via Table-Per-Type (TPT) inheritance mapping: public abstract class Company { public int TenantId { get; set; } public int CompanyId { get; set; } public int AddressId { get; set; } public Address Address { get; set; } } public class Customer : Company { public string CustomerName { get; set; }