不包含一个构造函数的参数2 [英] Does not contain a constructor that takes 2 arguments

查看:193
本文介绍了不包含一个构造函数的参数2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这里是什么发生。该模型是从数据库中自动生成的,我不能看到任何明显的(请注意这是凌晨2:30英国时间在此刻,所以也许我半睡半醒)。我得到的错误:ActiveCitizenSystemMimic.Models.ActiveCitizenProperties不包含一个构造函数2参数。

型号:

 命名空间ActiveCitizenSystemMimic.Models
{
    使用系统;
    使用System.Collections.Generic;    公共部分类ActiveCitizenProperties
    {
        公众诠释FK_ActiveCitizen {搞定;组; }
        公众诠释FK_PropertyType {搞定;组; }
    }
}

控制器:

 列表< ActiveCitizenProperties> activeCitizenProperties =新的List< ActiveCitizenProperties>();
activeCitizenProperties.Add(新ActiveCitizenProperties(1,2));


解决方案

您可能会取代你的code为:

 列表< ActiveCitizenProperties> activeCitizenProperties =新的List< ActiveCitizenProperties>();
activeCitizenProperties.Add(新ActiveCitizenProperties(){FK_ActiveCitizen = 1,FK_PropertyType = 2});

您自动生成级显然不包含一个构造函数2参数。如果有,它会是这样:

 命名空间ActiveCitizenSystemMimic.Models
{
    使用系统;
    使用System.Collections.Generic;    公共部分类ActiveCitizenProperties
    {
        公众诠释FK_ActiveCitizen {搞定;组; }
        公众诠释FK_PropertyType {搞定;组; }        公共ActiveCitizenProperties(INT A,INT B)
        {
            this.FK_ActiveCitizen =一个;
            this.FK_PropertyType = B;
        }
    }
}

I'm not sure what is occurring here. The model was auto generated from the database and I can't see anything obvious (mind you it is 2.30am UK time at the moment so maybe I'm half asleep). I am getting the error: ActiveCitizenSystemMimic.Models.ActiveCitizenProperties does not contain a constructor that takes 2 arguments.

Model:

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));

解决方案

You may replace your code to:

List<ActiveCitizenProperties> activeCitizenProperties = new List<ActiveCitizenProperties>();
activeCitizenProperties.Add(new ActiveCitizenProperties(){ FK_ActiveCitizen = 1, FK_PropertyType = 2 });

Your "auto-generated" class obviously doesn't contain a constructor that takes 2 arguments. If it has, it would be like this:

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;
        }
    }
}

这篇关于不包含一个构造函数的参数2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆