简体   繁体   中英

No parameterless constructor defined for this object

In my project, I create Linq-to-SQL classes using SqlMetal. The problem with this is that SqlMetal doesn't appear to create a parameterless constructor. I've always gotten around this because I can always get the default connectionstring name and pass it to the constructor - however, now I am being forced to use a LinqDataSource in markup, not code, so I can't specify a constructor.

Is there any way of forcing SQLMetal to generate a parameterless constructor?
Alternatively, flipping it on its head, is there actually a way of specifying a connection string in the markup, like this:

ContextTypeName="MyNameSpace.DAL(defaultconnStr)"

我认为您可以使用新的无参数构造函数创建局部类。

SqlMetal should have generated your Entities class using a partial class. You should be able to simply add a parameterless constructor in another partial class definition:

public partial class WhateverYourEntitiesAreCalledEntities():
    this(defaultConnStr)
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM