public JsonResult TestFunc(string str) { try { using (NetCoreContext context = new NetCoreContext()) { //var fsk = context.Set<Student>().Select(x => x.Name).FromSql<Student>("select Name from Student").ToList(); //IList<Student> test = fsk.Select(x => new { x.Name, x.Id }) as IList<Student>; IList <Student> dahd = context.Student.ToList(); //分页1 int pageSize = 10; int pageNum = 2; int offset = pageSize * (pageNum - 1); IList <Student> list = context.Student.Skip(offset).Take(pageSize).ToList(); //分页2 int pageSize2 = 5; int pageNum2 = 4; int offset2 = pageSize2 * (pageNum2 - 1); IList <Student> list2 = context.Student.Skip(offset2).Take(pageSize2).ToList(); //分页3 PageResult <Student> result = new PageResult <Student>(pageNum2, pageSize, context.Student); //sql执行 string sqlsql = "Select * From Student"; var dasjdla = context.Student.FromSql(sqlsql).ToList(); string sql = "Select s.*,c.Name As ClassName From Student As s Left Join Class As c On c.Id = s.ClassId"; var fdhskf = context.Stu.FromSql(sql).ToList(); IList <Stu> stundetList = context.Student.FromSql(sql).ToList() as IList <Stu>; //返回值:IQueryable<TEntity> var fdsfdsfds = context.Database.ExecuteSqlCommand(sql); //返回值:int return(this.Json(dahd)); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } throw new Exception(ex.Message); } }
public List <SysMenuDto> GetMenu() { List <SysMenuDto> result = new List <SysMenuDto>(); using (NetCoreContext db = new NetCoreContext()) { //一级菜单 List <SysMenu> lev1Menus = db.SysMenu.Where(x => x.MenuParentNo == null).ToList(); result = AutoMapper.Mapper.Map <List <SysMenuDto> >(lev1Menus); foreach (SysMenuDto lev1Menu in result) { //一级按钮 lev1Menu.BtnChildren = AutoMapper.Mapper.Map <List <SysButtonDto> >(db.SysButton.Where(x => x.MenuId == lev1Menu.Id).ToList()); //二级菜单 } } return(result); }
private static void CreateContext() { DbContextOptionsBuilder <NetCoreContext> contextOptionsBuilder = new DbContextOptionsBuilder <NetCoreContext>(); DbConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder() { DataSource = "localhost", IntegratedSecurity = true, InitialCatalog = "NETCoreTest", }; SqlConnection connection = new SqlConnection(connectionStringBuilder.ConnectionString); LoggerFactory loggerFactory = new LoggerFactory(); contextOptionsBuilder.UseLoggerFactory(loggerFactory); contextOptionsBuilder.UseSqlServer(connection); contextOptionsBuilder.EnableSensitiveDataLogging(); NetCoreContext context = new NetCoreContext(contextOptionsBuilder.Options); }
public FacturaController(NetCoreContext context) { _Factura = new FacturaRepository(context); }
public DetalleController(NetCoreContext context) { _Detalle = new DetalleRepository(context); }
public BookRepository(NetCoreContext context) : base(context) { }
public FacturaRepository(NetCoreContext context) : base(context) { }
public ClienteController(NetCoreContext context) { _Cliente = new ClienteRepository(context); }
public RepositoryBase(NetCoreContext context) { _context = context; }
public AuthorRepository(NetCoreContext context) : base(context) { }
public ProductoController(NetCoreContext context) { _Producto = new ProductoRepository(context); }
public DetalleRepository(NetCoreContext context) : base(context) { }
public AuthorsController(NetCoreContext context, IAuthorRepository authorRepository, IMapper mapper) { _context = context; _authorRepository = authorRepository; _mapper = mapper; }
public PersonaRepository(NetCoreContext context) { _dbContext = context; }
public PersonaController(NetCoreContext context) { _Persona = new PersonaRepository(context); }
public DetalleRepository(NetCoreContext context) { _dbContext = context; }
public ClienteRepository(NetCoreContext context) { _dbContext = context; }
public ClienteRepository(NetCoreContext context) : base(context) { }
public FacturaRepository(NetCoreContext context) { _dbContext = context; }
public ProductoRepository(NetCoreContext context) { _dbContext = context; }
public ProductoRepository(NetCoreContext context) : base(context) { }