using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DB.Model;
using System.Data;
using System.Data.Objects;
using System.Data.EntityClient;
using System.Web;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//using (DB.Model.pubsEntities pubs = new DB.Model.pubsEntities())
//{}
#region 增加
/*
DB.Model.Test test = new DB.Model.Test();
test.Name = "张三";
pubs.AddToTest(test);
pubs.SaveChanges();
Console.WriteLine(pubs.Test.ToTraceString());
*/
#endregion
#region 分页查询
/*
IList<DB.Model.Test> testList = pubs.Test.OrderByDescending(p=>p.ID).Skip(10).Take(10).ToList();
foreach (DB.Model.Test val in testList)
{
Console.WriteLine(val.Name);
}*/
#endregion
#region 聚合
// Console.WriteLine(pubs.Test.Max(p => p.ID));
#endregion
#region 多表连接
/*
var result = pubs.authors.Join(pubs.titleauthor, p => p.au_id, p => p.au_id, (p, k) => new { Authors = p, titleauthor = k })
.Take(10)
.ToList();
foreach (var s in result)
{
Console.WriteLine("id:{0},c:{1}", s.Authors.au_id, s.titleauthor);
}
*/
#endregion
#region 删除
/*
pubs.Test.DeleteObject(pubs.Test.Where(p => p.ID == 106939).First());
pubs.SaveChanges();
*/
#endregion
#region 修改
/*
DB.Model.Test test = pubs.Test.Where(p => p.ID == 106938).First();
test.Name = "TESTEST";
pubs.SaveChanges();
*/
#endregion
#region ESql
//ESql
//string strESql = "select value tit from pubsEntities.titles as tit";
//string strESql = "select value tit from pubsEntities.Test as tit where tit.id=@id";
//// string strESql = "select value key(tit) from pubsEntities.Test as tit order by tit.ID desc limit 20";
// string strEsql = "select value tit from pubsEntities.Test as tit where tit.id=-1";
// var result = pubs.CreateQuery<DB.Model.Test>(strEsql).FirstOrDefault();
//foreach (var val in result)
//{
// Console.WriteLine(val);
//}
//Console.WriteLine(pubs.Test.ToTraceString());
//System.Diagnostics.Debug.Assert(null != result, "First结果为NULL");
////Console.WriteLine(result.ID);
//string str1 = "select value tit from pubsEntities.Test as tit order by tit.id desc limit 10";
//string str2 = "select value tit from pubsEntities.Test as tit order by tit.id desc limit 20";
//var result = pubs.CreateQuery<DB.Model.Test>(str1).Intersect(pubs.CreateQuery<DB.Model.Test>(str2));
//System.Diagnostics.Debug.Assert(null != result, "差集为NUll");
//foreach (var r in result)
//{
// Console.WriteLine(r.ID);
//}
//Console.WriteLine(pubs.Test.ToTraceString());
#endregion
#region EntityClient
//l EntityConnection
//l EntityCommand
//l EntityConnectionStringBuilder
//l EntityParameter
//l EntityDataReader
//l EntityParameterCollection
//l EntityProviderFactory
//l EntityTransaction
DB.Model.pubsEntities pubs = new pubsEntities();
using (EntityConnection con = new EntityConnection(pubs.Connection.ConnectionString))
{
//Console.WriteLine(pubs.Connection.ConnectionString);
//string strSql = "select value tit from pubsEntities.Test as tit order by tit.id desc limit 20";
con.Open();
//EntityCommand cmd = new EntityCommand(strSql, con);
//var result = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
//while (result.Read())
//{
// Console.WriteLine(result[0]);
//}
//con.Close();
//var resultList = pubs.GetTestDataTop(MergeOption.NoTracking);
//foreach (var val in resultList)
//{
// Console.WriteLine(val.ID);
//}
//EntityKey key = new EntityKey("pubsEntities.Test", "Test.id", 1000);
//Console.WriteLine((pubs.GetObjectByKey(key) as DB.Model.Test).ID);
var exec = CompiledQuery.Compile<pubsEntities, IEnumerable<DB.Model.Test>>(p => p.Test.Where(k => k.ID >3000));
foreach (var s in exec(pubs))
{
Console.WriteLine(s.ID);
}
pubs.Refresh(RefreshMode.ClientWins, model);//并发处理方法
}
#endregion
}
}
}
学习地址
http://www.cnblogs.com/xray2005/archive/2009/05/07/1452033.html