using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Threading.Tasks; |
namespace DAL |
{ |
public partial class Test2Entities : System.Data.Entity.DbContext |
{ |
public Test2Entities() |
: base ( "name=Test2Entities" ) |
{ |
Database.SetInitializer<Test2Entities>( new System.Data.Entity.CreateDatabaseIfNotExists<Test2Entities>()); |
} |
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) |
{ |
//modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>(); |
} |
public virtual DbSet<ModelL.RoleSet> RoleSet { get ; set ; } |
public virtual DbSet<ModelL.UserSet> UserSet { get ; set ; } |
} |
public static class GetDbContext |
{ |
static Test2Entities _Test2DbContext = new Test2Entities(); |
public static Test2Entities Test2DbContext |
{ |
get { return _Test2DbContext; } |
} |
} |
public class RepositoryBase<T> : ModelL.IRepository<T> where T : class , new () |
{ |
Test2Entities _Test2DbContext = GetDbContext.Test2DbContext; |
public T Create() |
{ |
return _Test2DbContext.Set<T>().Create(); |
} |
public T Update(T entity) |
{ |
return entity; |
} |
public T Insert(T entity) |
{ |
return _Test2DbContext.Set<T>().Add(entity); |
} |
public void Delete(T entity) |
{ |
_Test2DbContext.Set<T>().Remove(entity); |
} |
public ModelL.ReturnMsg SaveChange() |
{ |
ModelL.ReturnMsg rm = new ModelL.ReturnMsg(); |
try |
{ |
int i = _Test2DbContext.SaveChanges(); |
rm.ErrCode = 0; |
rm.Successful = true ; |
rm.ErrMsg = "" ; |
} |
catch (Exception exc) |
{ |
rm.ErrCode = exc.HResult; |
rm.Successful = false ; |
rm.ErrMsg = exc.Message; |
} |
return rm; |
} |
public T Find( params object [] keyValues) |
{ |
return _Test2DbContext.Set<T>().Find(keyValues); |
} |
public T Find(Func<T, bool > predict) |
{ |
return _Test2DbContext.Set<T>().FirstOrDefault(predict); |
} |
public List<T> FindAll(Func<T, bool > predict) |
{ |
return _Test2DbContext.Set<T>().Where(predict).ToList(); |
} |
public List<T> FindAll() |
{ |
return _Test2DbContext.Set<T>().ToList(); |
} |
} |
public class RoleRepository : DAL.RepositoryBase<ModelL.RoleSet> |
{ |
} |
public class UserRepository : DAL.RepositoryBase<ModelL.UserSet> |
{ |
} |
} |
by: 发表于:2017-12-20 17:30:27 顶(0) | 踩(0) 回复
??
回复评论