// public List<EntityWithList<IEntityCommonInfo, IEntityCommonInfo>> GetMenuTree(object entity) { // var context = new SpecialistDataContext(); // var allForMenu = GetAllForMenu(); // var relations = allForMenu.GetValueOrDefault(Tuple.Create(entity.GetType(), // (int)LinqToSqlUtils.GetPK(entity))) ?? new List<SiteObjectRelation>(); // if(!relations.Any()) // return new List<EntityWithList<IEntityCommonInfo, IEntityCommonInfo>>(); // var tableNames = types.Select(x => SiteObject.TypeTableNames.GetValueOrDefault(x)) ; // var tree = relations.Where(x => tableNames.Contains(x.RelationObjectType)).Select(x => EntityWithList.New(x, // allForMenu.GetValueOrDefault(Tuple.Create(SiteObject.TableNameTypes[x.RelationObjectType], (int)x.RelationObject_ID)))); // var allrelations = tree.SelectMany(x => x.List.Concat(_.List(x.Entity))) // .ToList(); // var entityByType = new Dictionary<Type, Dictionary<object, IEntityCommonInfo>>(); // entityByType.Add(typeof (Section), // GetEntities<Section>(context, allrelations, x => x.Section_ID)); // entityByType.Add(typeof (Vendor), // GetEntities<Vendor>(context, allrelations, x => x.Vendor_ID)); // entityByType.Add(typeof (Product), // GetEntities<Product>(context, allrelations, x => x.Product_ID)); // entityByType.Add(typeof (SiteTerm), // GetEntities<SiteTerm>(context, allrelations, x => x.SiteTerm_ID)); // entityByType.Add(typeof (Profession), // GetEntities<Profession>(context, allrelations, x => x.Profession_ID)); // entityByType.Add(typeof (Course), // GetEntities<Course>(context, allrelations, x => x.Course_TC)); // // // Func<SiteObjectRelation, IEntityCommonInfo> getEntity = x => // entityByType[SiteObject.TableNameTypes[x.RelationObjectType]] // [x.RelationObject_ID]; // var entityWithTags = tree.Select(x => EntityWithList.New(getEntity(x.Entity), // x.List.Select(getEntity)/*.OrderBy(e => e.WebSortOrder)*/)).ToList(); // return entityWithTags; // } Dictionary <object, IEntityCommonInfo> GetEntities <T>(SpecialistDataContext context, List <SiteObjectRelation> allrelations, Func <T, object> idSelector) where T : class, IEntityCommonInfo { var ids = GetEntityIds(typeof(T), allrelations); if (!ids.Any()) { return(new Dictionary <object, IEntityCommonInfo>()); } return(Repository2 <T> .GetByPKList(context.GetTable <T>(), ids) .ToDictionary(idSelector, x => (IEntityCommonInfo)x)); }
public void Initialize() { IConfiguration ObjConfiguration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json") .Build(); string str = ObjConfiguration.GetConnectionString("Constr"); DbContextOptions <DBContext> options = new DbContextOptionsBuilder <DBContext>().UseSqlServer(str).Options; DBContext ObjContext = new DBContext(options); IRepository2 rp = new Repository2(ObjContext); Comp = new CompanyController(rp); ipo = new IPOController(rp); }
public Service1(Repository1 repository1, Repository2 repository2) { Repository1 = repository1; Repository2 = repository2; }