当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net core mvc - Using [ComplexType] in Entity Framework 7

问题描述:

I'm using a property of my own class inside EF7 data model.

public class Currency

{

public string Code { get; set; }

public string Symbol { get; set; }

public string Format { get; set; }

}

[ComplexType]

public class Money

{

public int? CurrencyID { get; set; }

public virtual Currency Currency { get; set; }

public double? Amount { get; set; }

}

public class Rate

{

public int ID { get; set; }

public Money Price = new Money();

}

My problem is that when I try to create a migration, EF7 reports a error.

Microsoft.Data.Entity.Metadata.ModelItemNotFoundException: The entity type 'RentABike.Models.Money' requires a key to be defined.

If I declare a key, a separate table for "Money" is created, which is not what I'm looking for.

Is there any way to use ComplexType in EF7 and put it all into a single table?

网友答案:

Support for complex types is currently on the backlog https://github.com/aspnet/EntityFramework/issues/246

分享给朋友:
您可能感兴趣的文章:
随机阅读: