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. SQL 循环插入10000条

    SQL> create table tt_test ( x int, y char(50) ); Table created. SQL> SQL> begin 2 for i in ...

  2. Python标准库os

    如果你希望自己的程序能够与平台无关的话,这个模块至关重要. os.name #'nt' for windows, 'posix' for linux/unix os.getcwd() #get cur ...

  3. 贴一段自动编译java,并混淆编译的代码

    刚写的一个自动编译.混淆.打包jar的代码,做个记录 用到的NuGet: <?xml version="1.0" encoding="utf-8"?> ...

  4. vue03 axios

    4. 通过axios实现数据请求 vue.js默认没有提供ajax功能的. 所以使用vue的时候,一般都会使用axios的插件来实现ajax与后端服务器的数据交互. 注意,axios本质上就是java ...

  5. C#当中的out关键字(借鉴于CSDN)

    一丶与ref关键字一样,out关键字也是按引用来传递的.out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数 ...

  6. LINUX C: 获取本地指定网卡的IP地址

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> ...

  7. P1638 逛画展

    题目描述 博览馆正在展出由世上最佳的 M 位画家所画的图画. wangjy想到博览馆去看这几位大师的作品. 可是,那里的博览馆有一个很奇怪的规定,就是在购买门票时必须说明两个数字, a和b,代表他要看 ...

  8. Spring 注解注入的几种方式(转)

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...

  9. 21.使用rescoring机制优化近似匹配搜索性能

        一.match和phrase match(proximity match)区别   1.match:只要简单的匹配到了一个term,就会将term对应的doc作为 结果返回. 2.phrase ...

  10. hdu 5179 beautiful number

    beautiful number 问题描述 令 A = \sum_{i=1}^{n}a_i * {10}^{n-i}(1\leq a_i \leq 9)A=∑​i=1​n​​a​i​​∗10​n−i​ ...