小编tim*_*ens的帖子

InvalidOperationException:无法将表“ xxxx1”用于实体类型“ xxxx2”,因为它已用于实体类型“ xxxx1”

我试图首先以实体框架代码创建数据库,但是我总是收到这样的错误:

InvalidOperationException:无法将表'Device'用于实体类型'IpMac',因为它已用于实体类型'Device',并且主键{'DeviceIP'}与主键{'DeviceID'}之间没有关系。”

这些是我的模型类:

public class IpMac
{
    [Key]
    public string DeviceIP { get; set; }
    //[ForeignKey("Device")]
    public int DeviceID { get; set; }
    public string DeviceMAC { get; set; }

    //public Device Device { get; set; }
    public ICollection<Device> Device { get; set; }
}
public class Device
{
    //[Key]
    public int DeviceID { get; set; }
    public string DeviceName { get; set; }
    public string UserName { get; set; }
    //public string DeviceMAC { get; set; }

    public IpMac …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework visual-studio ef-code-first

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