All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
技巧:ASP.NET里的Session详细解释_[Asp.Net教程]
控制电脑关机或者重新启动的JS代码_JavaScript技术_编程技术
操作数据:中级SQL_mssql学习_编程技术
php基础编程代码四则_[PHP教程]
Delphi以图形按钮显示的界面
扩展ASP.NET,2.0内置GridView控件之一_.net资料_编程技术
如何用VB存取SQL,Server中的图像数据_[Asp.Net教程]
asp.net使用代码从文件夹里读取图片_[Asp.Net教程]
SQL高级教程:SQL 撤销索引、表以及数据库_[SQL Server教程]
怎样用PHP来给网页做导航栏_php资料_编程技术
Reading number is top 10 pictures
The world's top ten most beautiful railway station1
NeedWallpaper10
水晶头骨造型的酒瓶
Summer is most suitable for young people to travel in China6
NeedWallpaper12
住院一星期,检测费两万
The money of more than 100 countries and regions4
Sell the barbecue as says father du breul1
The dog buy the ham oneself
女人化妆前后的对比
Download software ranking
少妇苏霞全本
Boxer Classic video2
Unix video tutorial15
C#COM编程指南
I for your crazy
Sora aoi's film--cangkong_Blue.Sky
Boxer's Top ten classic battle8
linux高级编程
都市狐狸姑娘传
天龙八部最新服务端
归海一刀 published in(发表于) 2014/1/30 0:52:57 Edit(编辑)
ASP.NET,MVC+LINQ开发一个图书销售站点(6)-创建数据层_[Asp.Net教程]

ASP.NET,MVC+LINQ开发一个图书销售站点(6)-创建数据层_[Asp.Net教程]

ASP.NET MVC+LINQ开发一个图书销售站点(6):创建数据层_[Asp.Net教程]

1. 我们在Model下存放我们系统需要的数据,首先我们创建一个数据库的Linq to Sql Class


image


2.选中所有的表到设计视图


image


3. 新建一个BookShopDBDataContext的分布类,我们在这里写一些方法和逻辑层Controller交互.


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

namespace BookShop.Models
{
public partial class BookShopDBDataContext
{
//return all categories
public List GetAllCategory()
{
return Categories.ToList();
}

//Add Category
public void AddCategory(Category c)
{

this.Categories.InsertOnSubmit(c);
this.SubmitChanges();
}

//Edit Category
public void EditCategory(Category c)
{

this.UpdateCategory(c);
this.SubmitChanges();
}

public Category GetCategory(int id)
{
return Categories.Single(c => c.CategoryId == id);
}

//delete category
public bool DelCategory(int id)
{

//check if has used
if (Books.Any(b => b.BookCategoryId == id))
{
return false;
}
else
{
Category delCategory = this.Categories.Single(c => c.CategoryId == id);
this.Categories.DeleteOnSubmit(delCategory);
this.SubmitChanges();
return true;
}
}
}
}





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.