自己动手搭建经典的3层 Asp.Net MVC
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Linq.Expressions; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace C01.ZRF.IDAL 9 { 10 public interface IBaseDAL<T> where T : class 11 { 12 13 int SaveChanges(); 14 15 void Add(T model); 16 17 void Delete(T model); 18 19 void DeleteBy(System.Linq.Expressions.Expression<Func<T, bool>> delWhere); 20 21 void Modify(T model, params string[] propertyNames); 22 23 IQueryable<T> Where(Expression<Func<T, bool>> whereLambda); 24 25 IQueryable<T> WhereOrder<TKey>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, TKey>> keySelector, bool isAsc = true); 26 27 IQueryable<T> WhereInclude(Expression<Func<T, bool>> whereLambda, params string[] includePropertyNames); 28 29 IQueryable<T> WhereInclude<TKey>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, TKey>> keySelector, bool isAsc = true, params string[] includePropertyNames); 30 31 IEnumerable<T> WherePaged<TKey>(int PageIndex, int PageSize, out int totalCount, Expression<Func<T, bool>> whereLambda, Expression<Func<T, TKey>> keySelector, bool isAsc = true, params string[] includePropertyNames); 32 33 IQueryable<T> QueryBySql(string sql, params System.Data.SqlClient.SqlParameter[] ps); 34 } 35 }
View CodeT4模板生成的接口
<#@ template language="C#" debug="false" hostspecific="true"#> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this); MetadataLoader loader = new MetadataLoader(this); CodeRegion region = new CodeRegion(this, 1); MetadataTools ef = new MetadataTools(this); string inputFile1 = @"E:\Temp\test01\3LaySolution\C10.ZRF.Model\Model1.edmx"; EdmItemCollection ItemCollection1 = loader.CreateEdmItemCollection(inputFile1); string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #> using System; using System.Collections.Generic; using System.Linq; using System.Text; using C10.ZRF.Model; namespace C01.ZRF.IDAL { <# foreach (EntityType entity in ItemCollection1.GetItems<EntityType>().OrderBy(e => e.Name)) { #> public partial interface I<#=entity.Name#>_DAL : IBaseDAL<<#=entity.Name#>>{ } <#}#> }
View Code生成后的效果如下:
温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/file/web/10311.html