using PMSWPF.Data.Entities; using PMSWPF.Excptions; namespace PMSWPF.Data.Repositories; public class DevicesRepositories:BaseRepositories { public DevicesRepositories():base() { var tableExist= _db.DbMaintenance.IsAnyTable(); if (!tableExist) { _db.CodeFirst.InitTables(); } } public async Task Add(DbDevice dbDevice) { var exist=await _db.Queryable().Where(d=>d.Name==dbDevice.Name).FirstAsync(); if (exist != null) { throw new DbExistException("设备名称已经存在。"); } var res= await _db.Insertable(dbDevice).ExecuteCommandAsync(); return res; } public async Task> GetAll() { return await _db.Queryable().ToListAsync(); } public async Task GetById(int id) { return await _db.Queryable().FirstAsync(p=>p.Id == id); } public async Task DeleteById(int id) { return await _db.Deleteable(new DbDevice() { Id = id }).ExecuteCommandAsync(); } }