我不确定这里发生了什么。该模型是从数据库自动生成的,我看不到任何明显的东西(请注意,此时此刻是英国时间凌晨2:30,所以我可能半睡着了)。我收到错误消息:ActiveCitizenSystemMimic.Models.ActiveCitizenProperties不包含带有2个参数的构造函数。
模型:
namespace ActiveCitizenSystemMimic.Models
{
using System;
using System.Collections.Generic;
public partial class ActiveCitizenProperties
{
public int FK_ActiveCitizen { get; set; }
public int FK_PropertyType { get; set; }
}
}
Controller :
List<ActiveCitizenProperties> activeCitizenProperties = new List<ActiveCitizenProperties>();
activeCitizenProperties.Add(new ActiveCitizenProperties(1, 2));
最佳答案
您可以将代码替换为:
List<ActiveCitizenProperties> activeCitizenProperties = new List<ActiveCitizenProperties>();
activeCitizenProperties.Add(new ActiveCitizenProperties(){ FK_ActiveCitizen = 1, FK_PropertyType = 2 });
您的“自动生成”类显然不包含带有2个参数的构造函数。如果有,它将是这样的:
namespace ActiveCitizenSystemMimic.Models
{
using System;
using System.Collections.Generic;
public partial class ActiveCitizenProperties
{
public int FK_ActiveCitizen { get; set; }
public int FK_PropertyType { get; set; }
public ActiveCitizenProperties(int a, int b)
{
this.FK_ActiveCitizen = a;
this.FK_PropertyType = b;
}
}
}
关于c# - 不包含带有2个参数的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14016475/