http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor

#region Assembly System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.Entity.dll
#endregion

ObjectContext类所处的命名空间System.Data.Objects

public partial class DB_COMAPEntities : ObjectContext

{

}

上面的类,无法通过编译,提示说,父类(ObjectContext)没有无参构造函数

DB_COMAPEntities 子类默认有一个无参构造函数,这个默认的无参构造函数去调用父类的无参构造函数。

而父类ObjectContext恰好没有无参构造函数,所以出错了。

解决方法:

显示指定调用的父类的有参构造函数,传递给父类有参构造函数的参数,是写死的常量。

public partial class DB_COMAPEntities : ObjectContext
{
public DB_COMAPEntities() : base("name=DB_COMAPEntities", "DB_COMAPEntities")
{ }
}

http://stackoverflow.com/questions/7689742/base-class-doesnt-contain-parameterless-constructor

class A
{
public A(int x, int y)
{
// do something
}
} class A2 : A
{
public A2() : base(, )
{
// do something
} public A2(int x, int y) : base(x, y)
{
// do something
} // This would not compile:
public A2(int x, int y)
{
// the compiler will look for a constructor A(), which doesn't exist
}
}

In class A2, you need to make sure that all your constructors call the base class constructor with parameters.

Otherwise, the compiler will assume you want to use the parameterless base class constructor to construct the A object on which your A2 object is based.

总结:

在父类没有无参构造函数的时候,子类的构造函数,必须显示指定如何调用父类的有参构造函数

Base Class Doesn't Contain Parameterless Constructor?的更多相关文章

  1. AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?

    问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...

  2. AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor

    System.ArgumentException HResult=0x80070057 Message=AddDbContext was called with configuration, but ...

  3. Base class does not contain a constructor that takes '0' argument

    刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...

  4. no parameterless constructor define for type 解决一例

    在生成根据模型和上下文生成带增删查改操作的视图的控制器时,提示上述信息,网上查找了资料也没有解决,突然想起该项目是连接MSSQL数据库和Redis数据库的,并且已经依赖注入了,而Redis数据库的服务 ...

  5. [Java Basics] Stack, Heap, Constructor, I/O, Immutable, ClassLoader

    Good about Java: friendly syntax, memory management[GC can collect unreferenced memory resources], o ...

  6. Virtual member call in a constructor

    http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor (Assuming you're writ ...

  7. Es6 类的关键 super、static、constructor、new.target

    ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...

  8. copy constructor

    copy constructor也分为trivial和nontrivial两种 如果class展现出bitwise copy semantics(按位拷贝语义),则不会构造出 copy constru ...

  9. Es6 类class的关键 super、static、constructor、new.target

    ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...

随机推荐

  1. Android RecyclerView利用Glide加载大量图片into(Target)导致OOM异常

    学过android的人应该都知道Glide是一个无比强大的图片加载库,它内部已经提供了很好的缓存机制供我们选择,我们只需一个参数调用即可(DiskCacheStrategy()),而不必像Univer ...

  2. html5——伸缩比例

    基本概念 1.父盒子设置了伸缩属性,子盒子设置伸缩比例 2.以上设置完之后子盒子会按照比例分布在父盒子中 3.当设置伸缩比例时默认会按照x轴方向分配,因为默认情况下伸缩布局主轴方向是x轴方向 4.设置 ...

  3. React-Native WebView动态加载字体

    背景 使用react-native构建的iOS/Android双端APP,通过WebView加载本地页面,需要根据服务器提供的字体列表实现下载和动态加载. 本地字体检查 有些字体手机操作系统已经提供了 ...

  4. 一个数据去重sql

    参考: https://www.jb51.net/article/129656.htm DELETE testcaseFROM testcase,  (  SELECT  max(id) id,  a ...

  5. CAD对象的夹点被编辑完成后调用事件(com接口VB语言)

    主要用到函数说明: _DMxDrawXEvents::ObjectGripEdit 对象的夹点被编辑完成后,会调用该事件,详细说明如下: 参数 说明 LONGLONG lId 对象的id LONG i ...

  6. Linux快速入门教程-进程管理ipcs命令学习

    使用Linux系统必备的技能之一就是Linux进程管理,系统运行的过程正是无数进程在运行的过程.这些进程的运行需要占用系统的内存等资源,做好系统进程的管理,对于我们合理分配.使用系统资源有非常大的意义 ...

  7. C++关键字:重学记录

    const_cast dynamic_cast explicit

  8. Python基础-画菱形

    方法一 n = int(input('请输入:')) for i in range(1, n, 2): print(('*'*i).center(n)) for i in reversed(range ...

  9. 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...

  10. elasticsearch match和match_phrase匹配原则(十)

    分词测试 分词后倒排索引结果:可以通过http://127.0.0.1:9200/_analyze 测试 { "analyzer":"ik_max_word", ...