Base Class Doesn't Contain Parameterless Constructor?
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?的更多相关文章
- 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 ... 
- 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 ... 
- Base class does not contain a constructor that takes '0' argument
		刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ... 
- no parameterless constructor define for type 解决一例
		在生成根据模型和上下文生成带增删查改操作的视图的控制器时,提示上述信息,网上查找了资料也没有解决,突然想起该项目是连接MSSQL数据库和Redis数据库的,并且已经依赖注入了,而Redis数据库的服务 ... 
- [Java Basics] Stack, Heap, Constructor, I/O, Immutable, ClassLoader
		Good about Java: friendly syntax, memory management[GC can collect unreferenced memory resources], o ... 
- Virtual member call in a constructor
		http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor (Assuming you're writ ... 
- Es6 类的关键 super、static、constructor、new.target
		ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ... 
- copy constructor
		copy constructor也分为trivial和nontrivial两种 如果class展现出bitwise copy semantics(按位拷贝语义),则不会构造出 copy constru ... 
- Es6 类class的关键 super、static、constructor、new.target
		ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ... 
随机推荐
- 关于用友 U8-UAP二开的一些事
			这是关于一个刚刚接触用友U8的二次开发的一些小心得. 首先就是用友二开的论坛,http://u8dev.yonyou.com/ 当然这个论坛做得不怎么样,提出了好几个问题,都没有回复的. 以下是关于二 ... 
- JS——缓慢动画封装案例
			手风琴 1.排他思想 2.ul宽度需要大一点,防止li撑开跑下去 3.一个变大其他所有变小,变小不能太小,不然会出现空白 <!DOCTYPE html> <html lang=&qu ... 
- 剔除重复jar包,查找重复类
			作为程序员,没有遇到过jar包冲突,不是你幸运,就是你还年轻. jar包冲突有着无穷的魔力,一提到就会有说不完的怨愤,道不清的忧伤,这都是内伤.jar 包冲突就像深藏地底的地雷,看上去平常无奇,一切是 ... 
- 3星|《商业周刊中文版:2017商业人物(下)》:酒店才应该是出行住宿的最佳选择,Airbnb不是
			商业周刊/中文版:2017商业人物(下) 对一些知名商业人物的访谈的合辑. 总体评价3星,有一些参考价值. 以下是本期一些内容的摘抄: 1:段永平是一位隐秘的亿万富豪,去年,他创立的智能手机姊妹品牌O ... 
- 实验1 C++函数
			一.实验目的: 掌握定义函数的方法.函数实参与形参的对应关系以及“值传递”的方式. 熟悉函数的嵌套调用和递归调用的方法. 熟悉全局变量.局部变量概念和使用方式. 二.实验内容: 运行调试第2章编程示例 ... 
- (转)Hibernate的优化方案
			http://blog.csdn.net/yerenyuan_pku/article/details/70768603 HQL优化 使用参数绑定 使用绑定参数的原因是让数据库一次解析SQL,对后续的 ... 
- 为.net mvc core 启用 https
			引用nuget包:Microsoft.AspNetCore.Server.Kestrel.Https这是一个服务器测试ssl密钥,密码如代码里面所示 using System; using Syste ... 
- VMware虚拟机下Ubuntu安装VMware Tools详解
			一.安装步骤 1.开启虚拟机,运行想要安装VMware Tools的系统,运行进入系统后,点击虚拟机上方菜单栏的“虚拟机(M)”->点击“安装 VMware Tools”,图片所示是因为我已经安 ... 
- C#基础速学
			原文地址 https://www.cnblogs.com/younShieh/p/10945264.html 前几天在刷即刻的时候发现了一个GitHub上的项目,该项目名为“learn x i ... 
- 关于read和fread
			1.fread与read的区别---open和fopen的区别--fread函数和fwrite函数:http://blog.csdn.net/dreamtdp/article/details/7560 ... 
