public List <string> GetUsers() { using (var db = new EFCoreContext()) { return(db.Users.Select(x => x.Username).ToList()); } }
public AccountService(AppConfiguration appConfiguration, EFCoreContext _db, DefaultRepository <Sys_UserRole> _dbUserRole, DefaultRepository <Sys_AppLog> _dbAppLog, IHttpContextAccessor iHttpContextAccessor) : base(_db) { this.appConfiguration = appConfiguration; this.dbUserRole = _dbUserRole; this.dbAppLog = _dbAppLog; this.httpContext = iHttpContextAccessor.HttpContext; this.Key = $"Authorization_{httpContext.Request.Host.Host}_{httpContext.Request.Host.Port}"; //获取 cookie var token = this.GetToken(); if (!string.IsNullOrWhiteSpace(token)) { var Id = new JwtTokenUtil().ReadJwtToken(token).ToGuid(); this.info = this.GetAccountByUserId(Id.ToGuid()).Result; } //if (httpContext.User != null) //{ // var claimsIdentity = httpContext.User.Identity as System.Security.Claims.ClaimsIdentity; // if (claimsIdentity.Name != null) // { // var Id = claimsIdentity.Name; // this.info = this.GetAccountByUserId(Id.ToGuid()).Result; // } //} }
public UserInfoService(EFCoreContext _db, IMapper _mapper, ILogger <UserInfoService> _log, IBaseService _baseService) { db = _db; mapper = _mapper; log = _log; baseService = _baseService; }
public void OnGet() { using (var context = new EFCoreContext()) { var estudiantes = context.Estudiantes.ToList(); } }
public List <Product> GetList() { using (var db = new EFCoreContext()) { return(db.Product.ToList()); } }
public override void CleanupTestDataSet() { using (var dataContext = new EFCoreContext()) { dataContext.Entities.RemoveRange(dataContext.Entities.ToList()); dataContext.SaveChanges(); } }
public List <Brand> GetList() { using (var db = new EFCoreContext()) { return(db.Brand.ToList()); } }
public List <Customer> GetUsersWithEF() { using (var db = new EFCoreContext()) { return(db.customers.FromSqlRaw("Select * from Customer").ToList()); } }
public static void Main(string[] args) { using (DbQueryCommit qc = new DbQueryCommit(new EFCoreContext())) { qc.Commit(() => { qc.Set <Blog>().Add(new Blog { Count = 1, Name = "CheckingDemo", Url = "http://welldone.org" }); }); var q = qc.Query <Blog>(1); q.ConsoleWriteLine(); } var ef = new EFCoreContext(); var blogs = ef.Blogs; var b1 = blogs.Skip(1).Take(1).ToList(); var b2 = blogs.Skip(10).Take(10).ToList(); Console.Read(); }
public BaseRepository(EFCoreContext eFCoreContext, IUnitOfWork unitOfWork) { _dbContext = eFCoreContext; _dbSet = _dbContext.Set <T>(); // _unitOfWork = new UnitOfWork(_dbContext); 此处会造成不同的UnitOfWork _unitOfWork = unitOfWork; }
public List <Category> GetList() { using (var db = new EFCoreContext()) { return(db.Categories.ToList()); } }
public ValuesController(IUserServices userServices, EFCoreContext context, IUserRepository userRepository, IRoleServices roleServices) { _userServices = userServices; _context = context; _user = userRepository; _roleServices = roleServices; }
public static void WriteVotesToFile() { if (!SetVotes()) { C.WL("No Data Readable"); return; } var OutputStrings = new string[Votes.Count]; foreach (var vote in Votes) { OutputStrings[Votes.IndexOf(vote)] = vote.Name.PadRight(20) + vote.CampusId + " Exam: " + vote.Exam + " Note: " + vote.Mark; } var session = new Session { ClassVotes = Votes, Date = DateTime.Now }; using (var dbcontext = new EFCoreContext()){//sqlite storage for testing dbcontext.Sessions.Add(session); dbcontext.SaveChanges(); } Program.ProgressBar(); var newFile = FilePath.Replace(Path.GetFileName(FilePath), $"Session{session.Id}.txt"); File.WriteAllLines(newFile, OutputStrings); C.WL("Done !"); reset(); }
public AccountService(EFCoreContext _db, DefaultRepository <Sys_UserRole> _dbUserRole, DefaultRepository <Sys_AppLog> _dbAppLog, IHttpContextAccessor iHttpContextAccessor) : base(_db) { this.dbUserRole = _dbUserRole; this.dbAppLog = _dbAppLog; this.httpContext = iHttpContextAccessor.HttpContext; this.Key = $"Authorization_{httpContext.Request.Host.Host}_{httpContext.Request.Host.Port}"; //获取 cookie var token = this.GetToken(); if (!string.IsNullOrWhiteSpace(token)) { var Id = new JwtTokenUtil().ReadJwtToken(token).ToGuid(); this.info = this.GetAccountByUserId(Id.ToGuid()).Result; } //if (httpContext.User != null) //{ // var claimsIdentity = httpContext.User.Identity as System.Security.Claims.ClaimsIdentity; // if (claimsIdentity.Name != null) // { // var Id = claimsIdentity.Name; // this.info = this.GetAccountByUserId(Id.ToGuid()).Result; // }Toolkit.ReadXmlSummary.XMLFromName(System.Type, char, string) (位于 [ReadXmlSummary.cs] 中)(navigate-to-context //} }
public override void TearDownSession() { if (dataContext != null) { dataContext.Dispose(); dataContext = null; } }
public Brand Add(Brand model) { using (var db = new EFCoreContext()) { db.Brands.Add(model); return(model); } }
public override void Bootstrap() { using var context = new EFCoreContext(DatabaseHelper.ConnectionString); context.Persons.FirstOrDefault(); context.Persons.AsNoTracking().FirstOrDefault(); context.Persons.FromSqlRaw("select * from Person").FirstOrDefault(); }
public async Task <Person> FirstAsync() { IncreaseId(); await using var context = new EFCoreContext(DatabaseHelper.ConnectionString); return(await context.Persons.FirstAsync(x => x.Id == CurrentId)); }
public Product GetProduct(int id) { using (var db = new EFCoreContext()) { var product = db.Products.Find(id); return(product); } }
public Person First() { IncreaseId(); using var context = new EFCoreContext(DatabaseHelper.ConnectionString); return(context.Persons.First(x => x.Id == CurrentId)); }
public Category GetCategory(int id) { using (var db = new EFCoreContext()) { var model = db.Categories.Find(id); return(model); } }
public Brand GetBrand(int id) { using (var db = new EFCoreContext()) { var brand = db.Brands.Find(id); return(brand); } }
public Brand Update(Brand model) { using (var db = new EFCoreContext()) { db.Brands.Update(model); return(model); } }
public bool InsertCustomer_EntityFramework() { using (var db = new EFCoreContext()) { var id = db.customers.Max(x => x.customerid); var customers = new[] { new Customer { slno = id + 1, customerid = id + 1, firstname = "Prathibha1", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 2, customerid = id + 2, firstname = "Prathibha2", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 3, customerid = id + 3, firstname = "Prathibha3", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 4, customerid = id + 4, firstname = "Prathibha4", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 5, customerid = id + 5, firstname = "Prathibha5", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 6, customerid = id + 6, firstname = "Prathibha6", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 7, customerid = id + 7, firstname = "Prathibha7", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 8, customerid = id + 8, firstname = "Prathibha8", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 9, customerid = id + 9, firstname = "Prathibha9", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 10, customerid = id + 10, firstname = "Prathibha10", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 11, customerid = id + 11, firstname = "Prathibha11", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 12, customerid = id + 12, firstname = "Prathibha12", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 13, customerid = id + 13, firstname = "Prathibha13", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 14, customerid = id + 14, firstname = "Prathibha14", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, new Customer { slno = id + 15, customerid = id + 15, firstname = "Prathibha15", middlename = "KB", lastname = "Raju", companyname = "Relyon", salesperson = "Sales1", emailaddress = "*****@*****.**", phone = "1111111111", modifieddate = DateTime.Now }, }; db.customers.AddRange(customers); return(db.SaveChanges() >= 0); } }
public void Test1() { EFCoreContext context = new EFCoreContext(); context.Database.EnsureDeleted(); //删除数据库 context.Database.EnsureCreated(); //新建数据库 //Assert.Pass(); }
public Category Update(Category model) { using (var db = new EFCoreContext()) { db.Categories.Update(model); db.SaveChanges(); return(model); } }
public Product Add(Product model) { using (var db = new EFCoreContext()) { db.Products.Add(model); db.SaveChanges(); return(model); } }
public Brand Update(Brand model) { using (var db = new EFCoreContext()) { db.Brand.Update(model); db.SaveChanges(); return(model); } }
public async Task <IActionResult> Index() { using (var context = new EFCoreContext()) { var model = await context.Authors.Include(a => a.Books).AsNoTracking().ToListAsync(); return(View(model)); } }
public Product Update(Product model) { using (var db = new EFCoreContext()) { db.Product.Update(model); db.SaveChanges(); return(model); } }