LINQ to SQL [综合]
2013-09-22 10:31
141 查看
最近学习 linq to sql 感觉还是可以的,方便快捷,以前问是以为不好用,不想用,但是今天用了一下感觉还是不错的, 确实是快,但是我又在想如果出错了怎么办,这样一个类里放那么多的文件是有点不好,再说了 linq to sql 低层不知道怎么实现的,还是没有自己写的访问感觉舒服点呵呵!!!如果是快速开发用 linq to sql 还是不错的选择啊!!!-基本的增删除改查
tc.ExecuteCommand("update table set sceState = 9 where sceState = 7");可以真写语句方便
2.TCDataClassesDataContext tc = new TCDataClassesDataContext(); tc.PGetAccountBalance(ofid).ToList()[0]
可以直接用存储过程的名称调用也很方便,呵呵。
大家有什么经验顶顶吧
http://www.sufeinet.com/forum.php?mod=viewthread&tid=129
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; namespace WebServiceText { /// <summary> /// Service1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { DataClasses1DataContext context = new DataClasses1DataContext(); [WebMethod] public List<Text> selectSwhere(int startid,int endid) { var result = (from text in context.Text where text.id >= startid && text .id <=endid select text).ToList<Text>(); return result; } [WebMethod] public List<Text> selectAll() { return context.Text.ToList<Text>(); } /// <summary> /// 添加一个数据 /// </summary> /// <param name="sex">性别</param> /// <param name="age">年龄</param> /// <returns>成功为True否则为False</returns> [WebMethod] public List<Text> addText(string sex, int age) { Text text = new Text(); text.age = age; text.sex = sex; //context.Text.First<Text>(); // 使用Sql方式查询 //var result = (from text in context.Text // select text).ToList<Text>(); // 提交一个插入 context.Text.InsertOnSubmit(text); // 更新数据库 context.SubmitChanges(); var result = context.Text.ToList<Text>(); return result; } /// <summary> /// 删除 /// </summary> /// <param name="id">根据ID做删除</param> /// <returns>成功为True否则为False</returns> [WebMethod] public List<Text> deleterText(int id) { // 删除 var text1 = (from t in context.Text where t.id == id select t).First<Text>(); context.Text.DeleteOnSubmit(text1); context.SubmitChanges(); var result = context.Text.ToList<Text>(); return result; } /// <summary> /// 修改Text /// </summary> /// <param name="id">编号</param> /// <param name="sex">性别</param> /// <param name="age">年龄</param> /// <returns>成功为True否则为False</returns> [WebMethod] public List<Text> updateText(int id, string sex, int age) { // 更新 var text = (from t in context.Text where t.id == id select t).First<Text>(); text.age = age; text.sex = sex; context.SubmitChanges(); var result = context.Text.ToList<Text>(); return result; } /// <summary> /// 查询 /// </summary> /// <param name="Swhere">条件</param> /// <returns>返回一个表</returns> [WebMethod] public List<Text> selectText(int id) { //使用Sql方式查询 var result = (from text in context.Text where text.id == id select text).ToList<Text>(); return result; } } }1. TCDataClasses1DataContext tc = new TCDataClasses1DataContext();
tc.ExecuteCommand("update table set sceState = 9 where sceState = 7");可以真写语句方便
2.TCDataClassesDataContext tc = new TCDataClassesDataContext(); tc.PGetAccountBalance(ofid).ToList()[0]
可以直接用存储过程的名称调用也很方便,呵呵。
大家有什么经验顶顶吧
http://www.sufeinet.com/forum.php?mod=viewthread&tid=129
相关文章推荐
- LinqToSql 动态查询条件,join, isnull 综合示例
- LINQ to SQL 成员资格
- 一步一步学Linq to sql(九):其它补充
- 一步一步学Linq to sql(六):探究特性
- LINQ to SQL可视化调试工具
- 一步一步学Linq to sql(一):预备知识
- LINQ to SQL之一
- LINQ-to-SQL那点事~目录
- 关于Linq to SQL 的“异常详细信息: System.InvalidCastException: 指定的转换无效。”
- linq to sql查询中返回linq自动建立的实体类型)
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 1)
- LINQ to SQL 数据库与LINQ对象的关系
- LINQ体验(12)——LINQ to SQL语句之对象标识和对象加载
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 4)
- LINQ to sql 系列随笔索引
- LINQ to SQL 查询数据库和使用存储过程
- 在.NET3.5平台上使用LinQ to SQL + NBear 创建三层WEB应用
- c#写webservice快速链接到数据库的方法Linq to Sql简单操作
- 深入理解 LINQ to SQL 生成的 SQL 语句
- LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作