代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
linqHelper
作者:
Ingram
/ 发布于
2016/1/8
/
1545
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Xml.Linq; using System.Collections.Generic; using System.Linq.Expressions; using System.Data.Linq; using Database; /// <summary> ///linqHelper 的摘要说明 a /// </summary> namespace Business { public abstract class linqHelper<TDatabase> where TDatabase : DataContext, new() { /// <summary> /// 查询全部数据 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static List<T> ReturnAllRows<T>(string conString) where T : class { TDatabase database = new TDatabase(); database.Connection.ConnectionString = conString; return database.GetTable<T>().ToList<T>(); } /// <summary> /// 查看是否存在数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="predicate"></param> /// <returns></returns> public static bool EntityExists<T>(string conString,Expression<Func<T, bool>> predicate) where T : class { TDatabase database = new TDatabase(); database.Connection.ConnectionString = conString; return database.GetTable<T>().Where<T>(predicate).Count() > 0; } /// <summary> /// 有条件的查询数据List<typeparamref name="数据源:DataContext"/> Filter<typeparamref name="表的类名:orders"/> /// 最后面的可以输入LINQ查询语句(p=>p.order_id="00001")或者(form o in orders where o.order_id>100 sleect o); /// </summary> /// <typeparam name="T"></typeparam> /// <param name="predicate"></param> /// <returns></returns> public static List<T> Filter<T>(string conString,Expression<Func<T, bool>> predicate) where T : class { TDatabase database = new TDatabase(); database.Connection.ConnectionString = conString; return database.GetTable<T>().Where(predicate).ToList<T>(); } /// <summary> /// 插入数据,好象只能一条,测试完弄个数据插入多条 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> public static void Insert<T>(string conString,T entity) where T : class { using (TDatabase database = new TDatabase()) { database.Connection.ConnectionString = conString; database.GetTable<T>().InsertOnSubmit(entity); database.SubmitChanges(); } } /// <summary> /// 删除指定数据,支持多条删除 Expression<Func<T, bool>> predicate就是查询语句,只能用:p=>p.user_id=="123"的语句! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="predicate"></param> ///返回值:0 成功 -1 失败 public static int Delete<T>(string conString,Expression<Func<T, bool>> predicate) where T : class { if (EntityExists<T>(conString, predicate)) { using (TDatabase database = new TDatabase()) { database.Connection.ConnectionString = conString; T t = (T)database.GetTable<T>().Where<T>(predicate).Single(); database.GetTable<T>().DeleteOnSubmit(t); database.SubmitChanges(); } return 0; } return -1; } /// <summary> /// 返回分页面数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pageSize">一次取多少条数据</param> /// <param name="currerCount">当前提交的页数字</param> /// <returns></returns> public static List<T> getpPgeRow<T>(string conString,int pageSize, int currerCount) where T : class { TDatabase database = new TDatabase(); database.Connection.ConnectionString = conString; return database.GetTable<T>().Skip<T>((currerCount - 1) * pageSize).Take<T>(pageSize).ToList<T>(); } /// <summary> /// 返回多少条数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="predicate"></param> /// <returns></returns> public static int getPageCount<T>(string conString,Expression<Func<T, bool>> predicate) where T : class { TDatabase database = new TDatabase(); database.Connection.ConnectionString = conString; return database.GetTable<T>().Where<T>(predicate).Count(); } /// <summary> /// 一次插入多条数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> public static void insetRows<T>(string conString,List<T> entity) where T : class { using (TDatabase database = new TDatabase()) { database.Connection.ConnectionString = conString; foreach(T t in entity.ToList()) { database.GetTable<T>().InsertOnSubmit(t); database.SubmitChanges(); } } } } }
试试其它关键字
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
Ingram
贡献的其它代码
(
7
)
.
list 去重
.
DataList项模板中的div在后台得到方法
.
百万级分页查询(Oracle)
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
StringHelper.cs 对html标签过滤
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3