不包含一个构造函数的参数2

编程入门 行业动态 更新时间:2024-10-24 06:38:10
本文介绍了不包含一个构造函数的参数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

本文发布于:2023-11-25 12:04:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不包含   函数   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!