这个orm已经用了好几个月了基本完善了,现在来分享下他的操作方式
Db.Instance.Insert<Message>()
.Add(o => o.Product, msg.Product)
.Add(o => o.Email, msg.Email)
.Add(o => o.Phone, msg.Phone)
.Add(o => o.Address, add.Area+add.Detail)
.Add(o => o.Content, msg.Content)
.Add(o => o.IP, ip)
.Add(o => o.CreateAt, DateTime.Now)
.Execute();
Db.Instance.Update<Article>(o => o.ArticleId == articleId)
.Add(o => o.ColumnId, columnId)
.Add(o => o.Title, title)
.Add(o => o.Content, content)
.Add(o => o.CreateAt, DateTime.Now)
.Execute() > 0;
Db.Instance.Insert(o);
Db.Instance.Update(o);
Db.Instance.Delete<Message>(o => o.MessageId == messageId);
Db.Instance.Query<Message>().OrderByDescending(o => o.CreateAt);
Db.Instance.Query<Message>().Where(o => o.MessageId == id).ToList();
var q = Db.Instance.Query<Product>().Where(o => o.SerialNumber.Contains(k) || o.Name.Contains(k) || o.ZhName.Contains(k) || o.EnName.Contains(k)).OrderByDescending(o=>o.CreateAt);
q.GetRange(pageIndex, pageSize).ToList();
.Add(o => o.Product, msg.Product)
.Add(o => o.Email, msg.Email)
.Add(o => o.Phone, msg.Phone)
.Add(o => o.Address, add.Area+add.Detail)
.Add(o => o.Content, msg.Content)
.Add(o => o.IP, ip)
.Add(o => o.CreateAt, DateTime.Now)
.Execute();
Db.Instance.Update<Article>(o => o.ArticleId == articleId)
.Add(o => o.ColumnId, columnId)
.Add(o => o.Title, title)
.Add(o => o.Content, content)
.Add(o => o.CreateAt, DateTime.Now)
.Execute() > 0;
Db.Instance.Insert(o);
Db.Instance.Update(o);
Db.Instance.Delete<Message>(o => o.MessageId == messageId);
Db.Instance.Query<Message>().OrderByDescending(o => o.CreateAt);
Db.Instance.Query<Message>().Where(o => o.MessageId == id).ToList();
var q = Db.Instance.Query<Product>().Where(o => o.SerialNumber.Contains(k) || o.Name.Contains(k) || o.ZhName.Contains(k) || o.EnName.Contains(k)).OrderByDescending(o=>o.CreateAt);
q.GetRange(pageIndex, pageSize).ToList();
Db.Instance 是根据webconfig里的第一个connection得到的
<add name="daogou" providerName="System.Data.SqlClient" connectionString="Data Source=xxx;User ID=xxx;Password=xxx;Initial Catalog=xxx;Pooling=true" />
也可以用new Db(string providerName, string connectionString)来得到实例,理论上支持所有的数据库,目前经过测试的有sqlserver,oledb,sqlite
本orm是基于表达式树开发的,经测试构造sql效率非常高,支持where,in,distinct,select field,top,order,max,count,contains(like),insert,delete,update,getrange等,就不一一示例。全部使用参数化查询
不过只支持单表操作,因为我个人不喜欢把业务逻辑放在sql语句里,支持事务(q.Attach(DbTransaction tran))。
最后感谢老赵在园子里写了那么多关于表达式树的文章!