Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
 }
Exemple #6
0
 public BookRepository(NetCoreContext context) : base(context)
 {
 }
 public FacturaRepository(NetCoreContext context) : base(context)
 {
 }
Exemple #8
0
 public ClienteController(NetCoreContext context)
 {
     _Cliente = new ClienteRepository(context);
 }
 public RepositoryBase(NetCoreContext context)
 {
     _context = context;
 }
 public AuthorRepository(NetCoreContext context) : base(context)
 {
 }
Exemple #11
0
 public ProductoController(NetCoreContext context)
 {
     _Producto = new ProductoRepository(context);
 }
Exemple #12
0
 public DetalleRepository(NetCoreContext context) : base(context)
 {
 }
Exemple #13
0
 public AuthorsController(NetCoreContext context, IAuthorRepository authorRepository, IMapper mapper)
 {
     _context          = context;
     _authorRepository = authorRepository;
     _mapper           = mapper;
 }
Exemple #14
0
 public PersonaRepository(NetCoreContext context)
 {
     _dbContext = context;
 }
Exemple #15
0
 public PersonaController(NetCoreContext context)
 {
     _Persona = new PersonaRepository(context);
 }
 public DetalleRepository(NetCoreContext context)
 {
     _dbContext = context;
 }
Exemple #17
0
 public ClienteRepository(NetCoreContext context)
 {
     _dbContext = context;
 }
Exemple #18
0
 public ClienteRepository(NetCoreContext context) : base(context)
 {
 }
 public FacturaRepository(NetCoreContext context)
 {
     _dbContext = context;
 }
Exemple #20
0
 public ProductoRepository(NetCoreContext context)
 {
     _dbContext = context;
 }
Exemple #21
0
 public ProductoRepository(NetCoreContext context) : base(context)
 {
 }