在Code First中使用Migrations对实体类和数据库做出变更
摘要:在Code First中使用Migrations对实体类和数据库做出变更,Mirgration包含一系列命令。 工具--库程序包管理器--程序包管理器控制台 运行命令:Enable-Migrations启用Code first Migration 运行成功后会产生两个类:Configuration.cs 和_InitialCreate.cs,这是一个用时间戳作为前缀的类。如201212310201487_InitialCreate.cs 然后更改实体类Blog,增加一个属性Url public class Blog { public int BlogId { get; s...
阅读全文
posted @
2013-08-20 10:54
cw_volcano
阅读(332)
推荐(0)
关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.
摘要:LINQ to Entities works by translating LINQ queries to SQL queries, then executing the resulting query on the database and converting the result back to application entities. Because of this crossover of two languages, it will only work when SQL-compatble method calls are made. When an incompatible c
阅读全文
posted @
2013-08-06 18:42
cw_volcano
阅读(443)
推荐(0)
Code generated using the T4 templates for Database First
摘要:Error message:Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing applic
阅读全文
posted @
2013-08-01 20:46
cw_volcano
阅读(693)
推荐(0)
Entity Framework快速入门笔记—增删改查
摘要:第一步:创建一个控制台应用程序,起名为EFDemo2. 第二步:创建一个实体模型 (1)在EFDemo项目上面右击选择添加—新建项—在已安装的选项中选择数据—ADO.NET实体对象模型,如图所示: 3. 与数据库进行连接 (1) 单击第二步建立的实体数据模型的添加按钮,然后我们选择从数据库生成,如图所示: (2) 单击下一步,然后如果我们以前没有操作的话在这里将是为空的,然后我们单击新建连接,建立一个数据库的链接,然后选择“是,在连接字符串中包含敏感数据”,如图所示: (3) 单击下一步,选择我们要生成实体框架对应的表,试图或者存储过程和函数,因为这里我只使用到了表,所以选择表的...
阅读全文
posted @
2013-06-27 17:40
cw_volcano
阅读(312)
推荐(0)
ADO.NET Entity Framework 中使用存储过程
摘要:本文主要介绍在ADO.NET Entity Framework中使用存储过程来进行查询、插入、更新、删除操作。使用一下SQL建立实例数据库,下面选择了Northwind库来执行SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Group]( [GroupID] [int] IDENTITY(1,1) NOT NULL, [GroupName] [nvarchar](20) NOT NULL,CONSTRAINT [PK_Group] PRIMARY KEY CLUSTERED ( [GroupID...
阅读全文
posted @
2013-04-16 09:59
cw_volcano
阅读(318)
推荐(0)
如何提高LINQ-to-SQL延时加载的性能
摘要:对于数据上下文DataContext来说,它有一个属性叫做DeferredLoadingEnabled,它的默认值为true,意思是开启模型的延时加载功能,例如:当你有一个对象Order_info,它有关系表Order_Detail,它们之间为一对多的关系,这在dbml模型中用EntitySet<T>来表示,意为实体的集合。而开启模型的延时加载功能时,只要你查询出Order_Info后,如果在前台使用到了Order_Detail,系统就会将Order_Detail的相关数据也查询出来,听上去不错,看代码:@foreach (var item in Model){ <p>
阅读全文
posted @
2013-03-25 21:25
cw_volcano
阅读(371)
推荐(0)
LINQ语句中的.AsEnumerable() 和 .AsQueryable()的区别
摘要:在写LINQ语句的时候,往往会看到.AsEnumerable() 和 .AsQueryable() 。例如:string strcon = "Data Source=.\\SQLEXPRESS;Initial Catalog=Db_Example;Persist Security Info=True;User ID=sa;Password=sa";SqlConnection con = new SqlConnection(strcon);con.Open();string strsql = "select * from SC,Course where SC.Cno
阅读全文
posted @
2012-10-09 17:53
cw_volcano
阅读(424)
推荐(0)
在DBML文件中快速定位到指定类
摘要:你是否有过从LINQ-TO-SQL的上千个表中找某个表而发愁呢,我是有过,确实很不好找,而且这方法的工具与说明文档非常少,工具有也是收费的,而做为“免费”的我们,从来对收费的概念是距而远之的。VS IDE是否有针对DBML文件的查找功能呢?对不起,这个查找对DBML是不灵的,呵呵,那是否有灵的呢,有,当然有,因为我已经找到了定位linq to sql实体的方法了,呵呵!在linq to sql的dbml文件空白处右击鼠标-》属性然后,我们可以在“属性”窗口中,选择你需要定位的类名,然后,它就会自己在模型中定位了,呵呵!
阅读全文
posted @
2012-10-02 01:48
cw_volcano
阅读(302)
推荐(0)
LINQ To SQL: Eager Loading
摘要:Eager loadingOne feature in ORM that's really useful and helps optimization is eager loading. The idea is quite simple, you define what objects in a graph you want to load for a single query and the ORM will make sure that the full graph is loaded after the query. Really efficient for graphs wit
阅读全文
posted @
2012-07-31 13:52
cw_volcano
阅读(1210)
推荐(0)
linq to xml
摘要:Linq To Xml学习 - 3.查询、更新、删除http://kb.cnblogs.com/page/42600/首先我们创建一个新窗体,这里以我的网站为例,我们起名叫Rss.aspx创建完成后,如果Rss数据源是XML实际文档,就跳过下面一步,如果Rss数据源是aspx文件请在创建完新页面后切换到源视图保留这一行:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Rss.aspx.cs"Inherits="Rss"%>其余的html代码全部删除
阅读全文
posted @
2012-04-30 21:24
cw_volcano
阅读(144)
推荐(0)
项目Contoso 大学
摘要:1.验证提示信息:View:<%=Html.ValidationSummary("") %>Controller:ModelState.AddModelError("Error", "您提交的信息还未通过审核!");if ((!this.ModelState.IsValid)) return this.RedirectWithErrors(this.View(DeleteViewName, viewModel), viewModel.GetErrors());2.确认数据库连接没有忘记关闭:protected overri
阅读全文
posted @
2012-02-01 08:56
cw_volcano
阅读(385)
推荐(1)
Linq返回指定类型
摘要:1.public IEnumerable<RiskInfo> GetRisksByUsername() { AuroraDataContext db = new AuroraDataContext(); var list = db.GetRisksByUsername().Select(c => new RiskInfo { Number = c.Number, Name = c.Name });return list; }public class RiskInfo { public int? Number { get; set; } public string Name {
阅读全文
posted @
2012-01-30 09:11
cw_volcano
阅读(383)
推荐(0)
Linq入门教程笔记
摘要:linq设计器生成的属性没有默认值,如getDate()将失效;可视化设计使用dbml文件, 保存后自动生成 [dbml名].design.cs后缀的代码文件, 生成的类都是部分类.同时允许我们手工添加 [dbml 名].cs文件,这个不会在dbml修改时被重写1.如果想自动创建数据库中两个表的关系...
阅读全文
posted @
2011-02-23 20:20
cw_volcano
阅读(573)
推荐(0)
Linq 笔记
摘要:提示错误 "The query results cannot be enumerated more than once."這段程式碼..會產生上面那段錯誤..原因就是aaaa被判斷成ISingleResult<T>的型別..而ISingleResult<T>不能被enumerate一次以上..所以就會發生exception..解決方法就是把ToList()這樣就行了.... var aaaa = db.StoredProcedure2().Select(a => a).ToList();13.Linq查询返回的是IEnumerable<T
阅读全文
posted @
2011-01-29 21:48
cw_volcano
阅读(337)
推荐(0)
Linq to Sql学习
摘要:LINQ to SQL语句(1)之WhereLINQ to SQL语句(2)之Select/DistinctLINQ to SQL语句(3)之Count/Sum/Min/Max/AvgLINQ to SQL语句(4)之JoinLINQ to SQL语句(5)之Order ByLINQ to SQL语句(6)之Group By/HavingLINQ to SQL语句(7)之Exists/In/Any/All/ContainsLINQ to SQL语句(8)之Concat/Union/Intersect/ExceptWhere操作适用场景:实现过滤,查询等功能。说明:与SQL命令中的Where作用
阅读全文
posted @
2011-01-29 16:31
cw_volcano
阅读(529)
推荐(0)