In part 1 we saw how DbContext.Database.Log can be used to easily log SQL to the console or some other TextWriter. This post covers how the context an... ...
分类:
数据库 时间:
2016-05-21 14:26:03
阅读次数:
302
In parts 1 and 2 of this series we looked at how to use DbContext.Database.Log to log the SQL generated by EF. But this code is actually a relatively ... ...
分类:
数据库 时间:
2016-05-21 14:25:27
阅读次数:
286
在MVC项目中使用ReportViewer 创建WebForm,向Webform中添加ReportViewer控件,通过CodeBehind设置报表参数并填充数据,测试通过后在MVC的View中iFrame新创建的WebForm 在MVC项目中使用使用DbContext作为ReportViewer的 ...
分类:
其他好文 时间:
2016-05-19 14:40:47
阅读次数:
136
开发环境 WIN10 Entity Framework6.0 MVC5.0 开发工具 VS2015 SqlServer2012 1.创建上下文Context继承DbContext,并创建其他的业务类,这些业务类会创建对应的数据表。 2.在web.config配置文件的entityFramework节 ...
分类:
数据库 时间:
2016-05-13 17:04:29
阅读次数:
1035
现在EF越来越流行了,很多时候业务成都是直接访问DbContext 和DbSet来操作数据的。 那么我们测试的时候如何来mock这2个对象了?现在时间很晚了, 就直接贴code吧:首先建一个帮助类:
public class MockedDbContext : Mock where T : DbContext
{
public Dictionarystring, o...
分类:
数据库 时间:
2016-05-12 20:41:05
阅读次数:
950
Code samples Create and initialize a DbContextThe connection string on the DbContext class can be initialized either by giving the connection string n ...
分类:
数据库 时间:
2016-05-03 12:23:08
阅读次数:
251
上篇介绍了一对一关系,下面介绍下一对多关系代码编写。 1、新建model实体,Product是产品类,Order是订单,一个产品对应多个订单 2、创建一个EntityContext并继承自DbContext 3、在web.config文件中添加数据库连接字符串 4、接着创建实体映射 5、我们写一些操 ...
分类:
其他好文 时间:
2016-05-02 15:34:29
阅读次数:
197
上篇介绍了一对多关系,下面介绍下多对多关系代码编写。 1、新建model实体,User是用户类,Role是角色类,由于是多对多关系,必须得有一个中间类,所以产生了UserRole类 2、创建一个EntityContext并继承自DbContext 3、在web.config文件中添加数据库连接字符串 ...
分类:
其他好文 时间:
2016-05-02 15:29:05
阅读次数:
229
下面新建两个实体,关系为一对一 Product为产品类,WarrantyCard为保修卡类,一个产品对应一个保修卡,一个保修卡对应一个产品。 1、新建实体类 2、创建EntityContext类并继承DbContext 3、在web.config文件中添加数据库连接字符串 4、创建表映射类 HasO ...
分类:
其他好文 时间:
2016-05-02 15:28:13
阅读次数:
118
首先配置连接数据、sql server 改写自动生成的代码拍段。因为他全部都继承DbContext类。 public class Employe { public int EmployId { get; set; } public string name { get; set; } public i ...
分类:
其他好文 时间:
2016-04-25 22:45:49
阅读次数:
187