本项目结合EF 4.3及WCF实现了经典三层架构,各层面向接口,WCF实现SOA,Repository封装调用,在此基础上实现了WCFContext,动态服务调用及一个分页的实例。
1. 项目架构图:
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' border="0" alt="" width="700" height="520" src="/uploadfile/201301/12/47123139714.jpg" />
2. 项目解决方案:
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' border="0" alt="" src="/uploadfile/201301/12/8C123139917.jpg" />
3. Wcf Service的实现:
498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' border="0" alt="" src="/uploadfile/201301/12/56123139551.jpg" />
- View Code
- public class DaoBase : IRepository, IDisposable
- {
- public DbContext context;
- public DaoBase()
- {
- this.context = new EasyEF.DAL.DbContext();
- }
- public T Update<T>(T entity) where T : class
- {
- var set = context.Set<T>();
- set.Attach(entity);
- context.Entry<T>(entity).State = EntityState.Modified;
- context.SaveChanges();
- return entity;
- }
- public T Insert<T>(T entity) where T : class
- {
- context.Set<T>().Add(entity);
- context.SaveChanges();
- return entity;
- }
- public void Delete<T>(T entity) where T : class
- {
- context.Entry<T>(entity).State = EntityState.Deleted;
- context.SaveChanges();
- }
- public T Find<T>(params object[] keyValues) where T : class
- {
- return context.Set<T>().Find(keyValues);
- }
- public List<T> FindAll<T>(Expression<Func<T, bool>> conditions = null) where T : class
- {
- if (conditions == null)
- return context.Set<T>().ToList();
- else
- return context.Set<T>().Where(conditions).ToList();
- }
- public PagedList<T> FindAllByPage<T, S>(Expression<Func<T, bool>> conditions, Expression<Func<T, S>> orderBy, int pageSize, int pageIndex) where T : class
- {
- var queryList = conditions == null ? context.Set<T>() : context.Set<T>().Where(conditions) as IQueryable<T>;
- return queryList.OrderByDescending(orderBy).ToPagedList(pageIndex, pageSize);
- }
- public void Dispose()
- {
- this.context.Dispose();
- }
4