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写法只是让对 ...
随机推荐
- SSH Secure Shell Client连接centos6.5时中文字乱码处理
在学习Linux的过程中,最先碰到的是通过SSH终端连接时发现有乱码出现,使用这篇文章先从这里说起. 在 ssh , telnet 终端中文显示乱码解决办法#vim /etc/sysconfig/i1 ...
- JS——缓慢动画封装
在知道如何获取内嵌式和外链式的标签属性值之后,我们再次封装缓慢动画: 单个属性 <!DOCTYPE html> <html> <head lang="en&qu ...
- 易语言 打开exe可执行文件、打开网页
打开文件--------按钮被单击事件 直接复制以下代码即可 .版本 2 .子程序 _按钮58_被单击 运行 (“exe文件路径”, 假, ) 打开网站--------按钮被单击事件 直接复制以下代码 ...
- 调用.NET Serviced Component引发的性能问题及其解决
在企业用户环境里,.NET Serviced Component使用广泛.它比较好的把传统COM+封装和.NET应用逻辑衔接了起来,在服务器端应用起到重要作用..NET Serviced Compon ...
- 使用super实现类的继承
查看一个类继承了哪些类可以用__bases__方法查看 class People: def __init__(self,name,age,sex): self.name=name self.ag ...
- 如何将工程推到github上
首先,读一下这个 Git-Pro中文版 步骤: 在本地文件系统中 git init 在github中新建项目(光新建就行了) 然后,出现下面这张图,打开sourceTree,按照上面的操作进行就行了. ...
- ionic 创建某个文件下的page
ionic g page 文件名 --pagesDir src/pages/about
- CentOS下使用yum安装配置和使用svn
安装说明 系统环境:CentOS-6.3安装方式:yum install (源码安装容易产生版本兼容的问题)安装软件:系统自动下载SVN软件 检查已安装版本 ? 1 2 3 4 5 6 7 8 9 1 ...
- Linux 下phpstudy的安装使用补充说明
(1)使用方法 在终端中使用sudo 或者 使用管理员账号运行 phpstudy start 开启 (2)命令列表: phpstudy start | stop | restart 开启 ...
- GFS分布式文件系统脚本
#!/bin/bashfor i in $(fdisk -l | grep -wo "/dev/sd[b-z]" | sort)dodd if=/dev/zero of=$i bs ...