public bool Insert(User_MODEL model) { using (EFDataContext dataContext = new EFDataContext()) { dataContext.User.Add(model); dataContext.SaveChanges(); return true; } }
public bool Update(MODEL.User_MODEL model) { using (EFDataContext dataContext = new EFDataContext()) { dataContext.Entry(model).State = EntityState.Modified; dataContext.SaveChanges(); return true; } }
/// <summary> /// 更新用户姓名 /// userModel 包含了已更新的Name /// </summary> /// <param name="userModel"></param> /// <returns></returns> public bool UpdateName(MODEL.User_MODEL userModel) { using (EFDataContext dataContext=new EFDataContext()) { dataContext.User.Attach(userModel); dataContext.Entry(userModel).Property(one => one.Name).IsModified = true; dataContext.SaveChanges(); return true; } }
public bool Delete(int id) { using (EFDataContext dataContext=new EFDataContext()) { MODEL.User_MODEL userModel = dataContext.User.Find(id); if (userModel != null) { dataContext.User.Remove(userModel); dataContext.SaveChanges(); return true; } return false; } }
/// <summary> /// 根据主键ID查找实体,然后更新其Name属性 /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <returns></returns> public bool UpdateName(int id, string name) { using (EFDataContext dataContext = new EFDataContext()) { MODEL.User_MODEL userModel = dataContext.User.Find(id); if (userModel != null) { dataContext.User.Attach(userModel); userModel.Name = name; dataContext.SaveChanges(); } return true; } }
public ActionResult Index() { _ctx = new EFDataContext(); var client = new Client("juan", "Ruiz", "brum", "095699447"); var pet = new Pet("arya", "9 meses", PetType.Cat); _ctx.Pets.Add(pet); client.Pets.Add(pet); _ctx.Clients.Add(client); _ctx.SaveChanges(); return View(); }
static void Main(string[] args) { using (var context = new Model1Container()) { IDataContext dataContext = new EFDataContext(context); IEmployeeRepository employeeRepo = new EmployeeRepository(dataContext); IEmailService emailService = new EmailService(); string ceoEmail = "*****@*****.**"; var task = new EmployeeBirthdayMailerTask(employeeRepo, emailService, ceoEmail); task.SendBirthdayGreetings(DateTime.Now.AddDays(1)); } }
public EFMemberRepository(EFDataContext context) { _context = context; }
public CarsController(EFDataContext context, IWebHostEnvironment webHostEnvironment) { _context = context; _webHostEnvironment = webHostEnvironment; }
public EFUnitOfWork(IConnectionStringProvider <string> connectionStringProvider, IMapper mapper) { _db = new EFDataContext(connectionStringProvider); Employees = new EFRepository <Employee, EmployeeEntity>(_db, mapper); Departments = new EFRepository <Department, DepartmentEntity>(_db, mapper); }
public CompetitionSubjectsController(EFDataContext context) { _context = context; }
public RepositoryUser(EFDataContext dbContext, IOptions <jwtCredentials> jwtCredentialsOptions) { _dbContext = dbContext; _jwtCredentials = jwtCredentialsOptions.Value; }
public PutWindow(long res, EFDataContext context) { InitializeComponent(); _res = res; _context = context; }
public UserService() { _context = new EFDataContext(); }
public int GetRecordCount(Where objWhere = null) { using (EFDataContext dataContext = new EFDataContext()) { if (objWhere == null) { objWhere = new Where().Add(new Where.Item("1", "=", "1")); } return dataContext.Database.SqlQuery<int>( $"select count({PrimaryKey}) from {TableName} where {objWhere.Result}", CreateWhereSqlParameters(objWhere)).First(); } }
public DataTable GetDataTable(string fields = "*", Where objWhere = null, string orderField = null, bool asc = true, int pageIndex = 0, int pageSize = 10) { using (EFDataContext dataContext = new EFDataContext()) { orderField = orderField ?? PrimaryKey; string sortDirection = asc ? "asc" : "desc"; string orderby = $" {orderField} {sortDirection} "; if (objWhere == null) { objWhere = new Where().Add(new Where.Item("1", "=", "1")); } string sql = $"select {fields} from {TableName} where {objWhere.Result}"; const string sqlPageBase = @"select * from( select *,ROW_NUMBER() OVER (ORDER BY {1}) as rank from ({0})a )as t where t.rank between {2} and {3}"; int startPageIndex = pageIndex*pageSize + 1; int endPageIndex = pageIndex*pageSize + pageSize; string sqlPage = string.Format(sqlPageBase, sql, orderby, startPageIndex, endPageIndex); return dataContext.Database.SqlQueryForDataTatable(sqlPage, CreateWhereSqlParameters(objWhere)); } }
public List<MODEL.User_MODEL> GetList( Where objWhere = null, string orderField = null, bool asc = true, int pageIndex = 0, int pageSize = 10) { using (EFDataContext dataContext = new EFDataContext()) { orderField = orderField ?? PrimaryKey; string sortDirection = asc ? "asc" : "desc"; string orderby = $" {orderField} {sortDirection} "; string where = (objWhere == null) ? "1=1" : objWhere.Result; string sql = $"select * from {TableName} where {where}"; const string sqlPageBase = @"select * from( select *,ROW_NUMBER() OVER (ORDER BY {1}) as rank from ({0})a )as t where t.rank between {2} and {3}"; int startPageIndex = pageIndex*pageSize + 1; int endPageIndex = pageIndex*pageSize + pageSize; string sqlPage = string.Format(sqlPageBase, sql, orderby, startPageIndex, endPageIndex); return (objWhere == null) ? dataContext.Database.SqlQuery<MODEL.User_MODEL>(sqlPage) //.Select(data => new User_MODEL() {Name = data.Name})//选取需要的字段 .ToList() : dataContext.Database.SqlQuery<MODEL.User_MODEL>(sqlPage, CreateWhereSqlParameters(objWhere)) //.Select(data => new User_MODEL() {Name = data.Name}) .ToList(); } }
public MainWindow() { InitializeComponent(); _context = new EFDataContext(); _window = new WindowModel(); }
public UnitOfWork() { _context = new EFDataContext(); }
public EFUnitOfWork(string connectionString) { db = new EFDataContext(connectionString); }
public PersonController(EFDataContext dbcontext) { _dbContext = dbcontext; }
public EFPurchaseRepository(EFDataContext context) { _context = context; }
public CatService() { _context = new EFDataContext(); }
public CompetitionFieldsController(EFDataContext context) { _context = context; }
public EFEntrustRepository(EFDataContext context) { _context = context; }
public CompetitionBranchesController(EFDataContext context) { _context = context; }
public EFProductRepository(EFDataContext context) { _context = context; }
public SupporterUsersController(EFDataContext context) { _context = context; }
public IrpfRepository() { _db = new EFDataContext(); }
public ProductRepository(EFDataContext context) { this.db = context; }
public EFWarehouseRepository(EFDataContext context) { _context = context; _setWerhouse = _context.Warehouse; }
public EFMemberRepository(EFDataContext dBContext) { _dBContext = dBContext; }
public EFBookCategoryRepository(EFDataContext dBContext) { _dBContext = dBContext; }
public SupporterUsersController(EFDataContext context, UserManager <Models.User> userManager) { _context = context; _userManager = userManager; }
public static void SeedAll(EFDataContext context) { SeedCats(context); }
public UserService(EFDataContext context) { _context = context; }
public EFGoodRepository(EFDataContext dataContext) { _dataContext = dataContext; }
public bool Delete(MODEL.User_MODEL userModel) { using (EFDataContext dataContext=new EFDataContext()) { dataContext.User.Attach(userModel); dataContext.User.Remove(userModel); dataContext.SaveChanges(); return true; } }
public RegistrationHandler(EFDataContext context, UserManager <AppUser> userManager, IJwtGenerator jwtGenerator) { _context = context; _userManager = userManager; _jwtGenerator = jwtGenerator; }
public MODEL.User_MODEL GetOne(int id) { using (EFDataContext dataContext = new EFDataContext()) { return dataContext.User.Find(id); } }
public ParticipantsController(EFDataContext context) { _context = context; }
// GET: Shop public ProductController(EFDataContext db) { this._db = db; }