LINQ错误:<< object>没有无参数的构造函数. [英] LINQ error: "<object> has no parameterless constructor."

查看:58
本文介绍了LINQ错误:<< object>没有无参数的构造函数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下定义的类方法GetMS(),但是调用该方法时出现错误,指出'SLRD' has no parameterless constructor.,我什至不理解为什么甚至调用了无参数构造函数.怎么了?

I have a class method GetMS() as defined below, but when the method is called I get an error stating 'SLRD' has no parameterless constructor. I don't understand why a parameterless constructor is even being called. What's wrong here?

public class SLR : BaseEntity
{
    // ...
    public virtual ICollection<SLRD> ChildRequests { get; set; }
}

public SLRD GetMS()
{
    return ChildRequests.First(c => c.Type == SLRTypes.MS);
}

推荐答案

您收到的错误非常清楚.您错过了定义无参数构造函数的过程.

The error you get is pretty clear. You missed to define a parameterless constructor.

public class SLR : BaseEntity
{
    public SLR() : base
    {
    }

    // ...
    public virtual ICollection<SLRD> ChildRequests { get; set; }
}

发生这种情况的原因是您的基类可能具有无参数构造函数.因此,您必须为派生类SLR定义一个.

The reason this is happens is the fact that your base class may have a parameterless constructor. So you have to define one for the derived class, SLR.

这篇关于LINQ错误:&lt;&lt; object&gt;没有无参数的构造函数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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