摘要: 外部映射文件 我们可以使用sqlmetal命令行工具来生成外部映射文件,使用方法如下:1、开始菜单 -》 VS2008 -》VS工具 -》VS2008命令行提示2、输入命令:D:\Program Files\Microsoft Visual Studio 9.0\VC>sqlmetal /conn:server=xxx;database=Northwind;uid=xxx;pwd=xxx /map:c:\northwind.map /code:c:\northwind.cs3、这样,我们就可以在C盘下得到一个xml映射文件和C#的实体类代码4、把.cs文件添加到项目中来(放到App_Co 阅读全文
posted @ 2011-05-18 15:33 Kingdom_0 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 论坛表结构 为了演示继承与关系,我们创建一个论坛数据库,在数据库中创建三个表:1、 论坛版块分类表 dbo.Categories:字段名字段类型可空备注CategoryIDintnot nullidentity/主键CategoryNamevarchar(50)not null2、 论坛版块表 dbo.Boards:字段名字段类型可空备注BoardIDintnot nullidentity/主键BoardNamevarchar(50)not nullBoardCategoryintnot null对应论坛版块分类表的CategoryID3、 论坛主题表 dbo.Topics:字段名字段类型可空 阅读全文
posted @ 2011-05-18 15:16 Kingdom_0 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 检测并发 首先使用下面的SQL语句查询数据库的产品表:select * from products where categoryid=1 查询结果如下图: 为了看起来清晰,我已经事先把所有分类为1产品的价格和库存修改为相同值了。然后执行下面的程序: var query = from p in ctx.Products where p.CategoryID == 1 select p; foreach (var p in query) p.UnitsInStock = Convert.ToInt16(p.UnitsInStock - 1); ctx.SubmitChanges(); // 在这里 阅读全文
posted @ 2011-05-18 14:17 Kingdom_0 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 延迟执行 IQueryable query = from c in ctx.Customers select c; 这样的查询句法不会导致语句立即执行,它仅仅是一个描述,对应一个SQL。仅仅在需要使用的时候才会执行语句,比如: IQueryable query = from c in ctx.Customers select c; foreach (Customer c in query) Response.Write(c.CustomerID); 如果你执行两次foreach操作,将会捕获到两次SQL语句的执行: IQueryable query = from c in ctx.Custom 阅读全文
posted @ 2011-05-18 11:27 Kingdom_0 阅读(147) 评论(0) 推荐(1) 编辑