小编Mat*_*ker的帖子

EF首先使用代码与一对多关系创建重复的外键

我正在使用以下类来实现一对多关系:

public class Supplier
{
    public Supplier()
    {
        SupplierId = Guid.NewGuid();
    }

    public Guid SupplierId { get; set; }
    [Required]
    public string Name { get; set; }

    [Required]
    public virtual Address Address { get; set; }

    public virtual ICollection<Contact> Contacts { get; set; }
}

public class Contact
{
    public Contact()
    {
        ContactId = Guid.NewGuid();
    }

    public Guid ContactId { get; set; }

    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }

    [Required] …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc entity-framework ef-code-first

5
推荐指数
1
解决办法
3493
查看次数