好久没有写东西了,不是自己不想写,是自己好像对语文描述能力确实有点差劲.进园子那么久也没有写过完全是自己的东西.都快用
COPY,PARSTER用到极致了.
也罢,就把最近用的东西写写吧.最近研究了一下LINQ表达式的一些编程方式,了解ExpressionVisitor类的主要功能及其实现.从而写了一个自己的LINQ框架,用LINQ的方式编程进而生成相应的SQL语句来达到访问数据库的目的.其写法类似于IEnumerable<T>的写法.下面是相关例子
var person = DMS.Create().Join(DMS.Create (), (x, y) => x.PersonID == y.PersonID , (x, y) => new { x.PersonID, x.Remark, x.StudentID, y.Name, y.Age });
调用 person.GetResultSql()
生成的Sql如下:
SELECT [t0].[PersonID],[t0].[Remark],[t0].[StudentID],[t1].[Name],[t1].[Age] FROM [Student] AS [t0] INNER JOIN [Person] AS [t1] ON ([t0].[PersonID] = [t1].[PersonID])
下面是两个相关的类:
1 [TableMapping(Name = "Person", PrimaryKey = "PersonID", DefaultOrderBy = " PersonID Desc")] 2 public class Person : BaseEntity 3 { 4 [ColumnMapping(Name = "PersonID")] 5 public int PersonID { get; set; } 6 [ColumnMapping(Name = "Name")] 7 public string Name { get; set; } 8 [ColumnMapping(Name = "Age")] 9 public int Age { get; set; }10 }11 12 [TableMapping(Name = "Student", PrimaryKey = "StudentID", DefaultOrderBy = " StudentID Desc")]13 public class Student : BaseEntity14 {15 [ColumnMapping(Name = "StudentID")]16 public int StudentID { get; set; }17 [ColumnMapping(Name = "PersonID")]18 public int PersonID { get; set; }19 [ColumnMapping(Name = "Remark")]20 public string Remark { get; set; }21 }
这里建立Mapping主要是为确定列名和表名,当然我们也可以直接使用PropertyInfo.Name来进行替代..
Listlist = new List (); var a = DMS.Create () .Where(q => q.PersonID == 0) .OrderBy(q => q.Columns(q.PersonID)); list.Add(a); var b = DMS.Create ().Select(q => q.Columns(q.Age, q.Name, q.PersonID)); list.Add(b); var c = DMS.Create (false) .Where(q => q.Name.Like("123")) .Select(); list.Add(c); var d = DMS.Create () .Join(DMS.Create () , (x, y) => x.PersonID == y.PersonID , (x, y) => new { x.PersonID, x.Name, x.Age, y.Remark, y.StudentID, PersonID2 = y.PersonID }).OrderBy(q => q.OrderBy(q.PersonID.Desc())).Pager(5, 20); list.Add(d); foreach (DMS item in list) { Console.WriteLine(item.GetResultSql()); } Console.ReadLine();
这些只是这个DMSLINQ的一些简单功能,DMSLinq还可以生成更复杂的SQL语句.这里就不再叙述了..哈哈..
后续文章将为您慢慢揭开DMSLinq的奥秘.....
相关项目下载可以联系本人QQ.因花的时间比较多在这块.
因现在项目大部分还是3.5特此做了一个3.5版本的,调试了一上基本正常
帮助文档: