public LmsAdminGroupRepo(EcatContext mainCtx)//, BbWsCnet bbWs) { ctxManager = new EFPersistenceManager <EcatContext>(mainCtx); //_bbWs = bbWs; Faculty = ctxManager.Context.Faculty.Where(f => f.PersonId == loggedInUserId).SingleOrDefault(); }
public List <Employee> QueryInvolvingMultipleEntities() { #if NHIBERNATE // need to figure out what to do here //return new List<Employee>(); var dc0 = new NorthwindNHContext(); var dc = new NorthwindNHContext(); #elif CODEFIRST_PROVIDER var dc0 = new NorthwindIBContext_CF(); var dc = new EFPersistenceManager <NorthwindIBContext_CF>(); #elif DATABASEFIRST_OLD var dc0 = new NorthwindIBContext_EDMX(); var dc = new EFContextProvider <NorthwindIBContext_EDMX>(); #elif DATABASEFIRST_NEW var dc0 = new NorthwindIBContext_EDMX_2012(); var dc = new EFContextProvider <NorthwindIBContext_EDMX_2012>(); #elif ORACLE_EDMX var dc0 = new NorthwindIBContext_EDMX_Oracle(); var dc = new EFContextProvider <NorthwindIBContext_EDMX_Oracle>(); #endif //the query executes using pure EF var query0 = (from t1 in dc0.Employees where (from t2 in dc0.Orders select t2.EmployeeID).Distinct().Contains(t1.EmployeeID) select t1); var result0 = query0.ToList(); //the same query fails if using EFContextProvider dc0 = dc.Context; var query = (from t1 in dc0.Employees where (from t2 in dc0.Orders select t2.EmployeeID).Distinct().Contains(t1.EmployeeID) select t1); var result = query.ToList(); return(result); }
public List <Employee> QueryInvolvingMultipleEntities() { var dc0 = new NorthwindIBContext_CF(PersistenceManager.Context.Options); var pm = new EFPersistenceManager <NorthwindIBContext_CF>(dc0); //the query executes using pure EF var query0 = (from t1 in dc0.Employees where (from t2 in dc0.Orders select t2.EmployeeID).Distinct().Contains(t1.EmployeeID) select t1); var result0 = query0.ToList(); //the same query fails if using EFContextProvider dc0 = pm.Context; var query = (from t1 in dc0.Employees where (from t2 in dc0.Orders select t2.EmployeeID).Distinct().Contains(t1.EmployeeID) select t1); var result = query.ToList(); return(result); }
/// <summary> /// This method will invoke the Breezer.WebApi.EFContextProvider extract the csdl fot the type /// </summary> /// <param name="type">The type to extract the csdl for</param> /// <returns>The metadata, or an empty string</returns> /// <remarks> /// When using a DbFirst approach EF thwros two kind of exceptions: /// 1. InvalidOperationException is there is no connection string for the DbContext we are working on. /// 2. UnintentionalCodeFirstException if it finds the connection string for the DbContext. /// UnintentionalCodeFirstException inherits from InvalidOperationException /// </remarks> private static string GetMetadataFromType(Type type) { try { if (type.BaseType == typeof(System.Data.Entity.DbContext) || type == typeof(ObjectContext)) //project is using EF6 { var providerType = typeof(EFContextProvider <>).MakeGenericType(type); var provider = (ContextProvider)Activator.CreateInstance(providerType); var metadata = provider.Metadata(); return(metadata); } else if (type.BaseType == typeof(Microsoft.EntityFrameworkCore.DbContext)) //project is using EF Core { var provider = (Microsoft.EntityFrameworkCore.DbContext)Activator.CreateInstance(type); var pm = new EFPersistenceManager <Microsoft.EntityFrameworkCore.DbContext>(provider); var metadata = pm.Metadata(); return(metadata); } else { Console.WriteLine("Could not interpret database context"); return(null); } } //catch (InvalidOperationException iex) // This is might be because we have a DbFirst DbContext, so let's try it out. //{ // try { // return EFContextProvider<object>.GetMetadataFromDbFirstAssembly(type.Assembly, Options.ResourcePrefix); // } // catch (Exception ex) { // Console.WriteLine("An exception was thrown while processing the dbfirst assembly {0}. {1}", type.Assembly.FullName, ex); // } //} catch (Exception ex) { Console.WriteLine("An exception was thrown while processing {0}. {1}", type.FullName, ex); } return(string.Empty); }
//inject the context public ProductRepository(ProductContext productContext) { //new up the breeze manager using the context _persistenceManager = new EFPersistenceManager <ProductContext>(productContext); }
public StudentRepo(EcatContext context) { ctxManager = new EFPersistenceManager <EcatContext>(context); }
public NorthwindController(ILogger <NorthwindController> logger, NorthwindDbContext context) { _logger = logger; Context = context; PersistenceManager = new EFPersistenceManager <NorthwindDbContext>(context); }
public MonitoredGuard(EFPersistenceManager <EcatContext> efCtx) { ctxManager = efCtx; }
public UserGuard(EFPersistenceManager <EcatContext> efCtx, int userId) { ctxManager = efCtx; //_loggedInUser = loggedInUser; loggedInUserId = userId; }
public FacultyRepo(EcatContext context) { ctxManager = new EFPersistenceManager <EcatContext>(context); }
public FacultyGuard(EFPersistenceManager <EcatContext> efCtx, int userId) { ctxManager = efCtx; loggedInUserId = userId; }
public DataServiceController(QueryStatsContext context) { _efPersistenceManager = new EFPersistenceManager <QueryStatsContext>(context); }
public static SaveMap Publish(SaveMap wgSaveMap, IEnumerable <int> svrWgIds, int loggedInPersonId, EFPersistenceManager <EcatContext> ctxProvider) { var infos = wgSaveMap.Single(map => map.Key == tWg).Value; var pubWgs = GetPublishingWgData(svrWgIds, ctxProvider); if (pubWgs == null) { var errorMessage = "The database did not return a publishable workgroup."; var error = infos.Select( info => new EFEntityError(info, "Publication Error", errorMessage, "MpSpStatus")); throw new EntityErrorsException(error); } foreach (var wg in pubWgs) { var stratScoreInterval = 1m / wg.PubWgMembers.Count(); stratScoreInterval = decimal.Round(stratScoreInterval, 4); var stratKeeper = new List <PubWgMember>(); var countOfGrp = wg.PubWgMembers.Count(); var totalStratPos = 0; for (var i = 1; i <= countOfGrp; i++) { totalStratPos += i; } foreach (var me in wg.PubWgMembers) { var stratSum = me.PubStratResponses.Sum(strat => strat.StratPosition); stratSum += me.SelfStratPosition; if (me.PeersDidNotAssessMe.Any() || me.PeersIdidNotAssess.Any() || me.PeersDidNotStratMe.Any() || me.PeersIdidNotStrat.Any() || me.FacStratPosition == 0 || stratSum != totalStratPos) { var errorMessage = $"There was a problem validating necessary information . Problem Flags Are: [Them => Me] NA: !{me.PeersDidNotAssessMe.Count()}, NS: {me.PeersDidNotStratMe.Any()} | [Me => Them] NA: {me.PeersIdidNotAssess.Count()}, NS: {me.PeersIdidNotStrat.Any()} | FacStrat: {me.FacStratPosition}"; var error = infos.Select( info => new EFEntityError(info, "Publication Error", errorMessage, "MpSpStatus")); throw new EntityErrorsException(error); } var peerCount = countOfGrp - 1; var resultScore = ((decimal)me.SpResponseTotalScore / (me.CountSpResponses * 6)) * 100; var spResult = new SpResult { CourseId = wg.CourseId, WorkGroupId = wg.Id, StudentId = me.StudentId, AssignedInstrumentId = wg.InstrumentId, CompositeScore = (int)resultScore, BreakOut = new SpResultBreakOut { NotDisplay = me.BreakOut.NotDisplayed, IneffA = me.BreakOut.IneffA, IneffU = me.BreakOut.IneffU, EffA = me.BreakOut.EffA, EffU = me.BreakOut.EffU, HighEffA = me.BreakOut.HighEffA, HighEffU = me.BreakOut.HighEffU }, MpAssessResult = ConvertScoreToOutcome((int)resultScore), }; var resultInfo = ctxProvider.CreateEntityInfo(spResult, me.HasSpResult ? EntityState.Modified : EntityState.Added); resultInfo.ForceUpdate = me.HasSpResult; if (!wgSaveMap.ContainsKey(tSpResult)) { wgSaveMap[tSpResult] = new List <EntityInfo> { resultInfo }; } else { wgSaveMap[tSpResult].Add(resultInfo); } var stratResult = new StratResult { CourseId = wg.CourseId, StudentId = me.StudentId, WorkGroupId = wg.Id, ModifiedById = loggedInPersonId, ModifiedDate = DateTime.Now, StratCummScore = decimal.Round(me.StratTable.Select(strat => { var multipler = 1 - (strat.Position - 1) * stratScoreInterval; return(multipler * strat.Count); }).Sum(), 4) }; me.StratResult = stratResult; stratKeeper.Add(me); } var cummScores = new List <decimal>(); var oi = 1; foreach (var strat in stratKeeper.OrderByDescending(sk => sk.StratResult.StratCummScore)) { if (cummScores.Contains(strat.StratResult.StratCummScore) || !cummScores.Any()) { strat.StratResult.OriginalStratPosition = oi; cummScores.Add(strat.StratResult.StratCummScore); continue; } ; cummScores.Add(strat.StratResult.StratCummScore); oi += 1; strat.StratResult.OriginalStratPosition = oi; } var fi = 0; var spInterval = wg.WgSpTopStrat / wg.StratDivisor; var facInterval = wg.WgFacTopStrat / wg.StratDivisor; foreach ( var gm in stratKeeper.OrderByDescending(sk => sk.StratResult.StratCummScore) .ThenBy(sk => sk.FacStratPosition)) { var studAwardedPoints = Math.Max(0, wg.WgSpTopStrat - spInterval * fi); var instrAwardPoints = Math.Max(0, wg.WgFacTopStrat - (facInterval * (gm.FacStratPosition - 1))); //var totalAward = studAwardedPoints + instrAwardPoints; gm.StratResult.StudStratAwardedScore = studAwardedPoints; gm.StratResult.FacStratAwardedScore = instrAwardPoints; gm.StratResult.FinalStratPosition = fi + 1; var info = ctxProvider.CreateEntityInfo(gm.StratResult, gm.HasStratResult ? EntityState.Modified : EntityState.Added); info.ForceUpdate = gm.HasStratResult; if (!wgSaveMap.ContainsKey(tStratResult)) { wgSaveMap[tStratResult] = new List <EntityInfo> { info }; } else { wgSaveMap[tStratResult].Add(info); } fi += 1; } } return(wgSaveMap); }
private static IEnumerable <PubWg> GetPublishingWgData(IEnumerable <int> wgIds, EFPersistenceManager <EcatContext> ctxManager) { var ids = wgIds.ToList(); var pubWgData = (from wg in ctxManager.Context.WorkGroups let prundedGm = wg.GroupMembers.Where(gm => !gm.IsDeleted) where ids.Contains(wg.WorkGroupId) && wg.MpSpStatus == MpSpStatus.UnderReview && wg.SpComments.Where(spc => !spc.Author.IsDeleted && !spc.Recipient.IsDeleted).All(comment => comment.Flag.MpFaculty != null) select new PubWg { Id = wg.WorkGroupId, CourseId = wg.CourseId, CountInventory = wg.AssignedSpInstr.InventoryCollection.Count, InstrumentId = wg.AssignedSpInstrId, WgSpTopStrat = wg.WgModel.MaxStratStudent, WgFacTopStrat = wg.WgModel.MaxStratFaculty, StratDivisor = wg.WgModel.StratDivisor, PubWgMembers = wg.GroupMembers.Where(gm => !gm.IsDeleted).Select(gm => new PubWgMember { StudentId = gm.StudentId, Name = gm.StudentProfile.Person.LastName + gm.StudentProfile.Person.FirstName, CountSpResponses = gm.AssesseeSpResponses .Count(response => response.AssessorPersonId != gm.StudentId), SpResponseTotalScore = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != gm.StudentId) .Sum(response => response.ItemModelScore), FacStratPosition = gm.FacultyStrat.StratPosition, HasSpResult = wg.SpResults.Any(result => result.StudentId == gm.StudentId), HasStratResult = wg.SpStratResults.Any(result => result.StudentId == gm.StudentId), BreakOut = new PubWgBreakOut { NotDisplayed = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Nd), IneffA = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Iea), IneffU = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Ieu), EffA = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Ea), EffU = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Eu), HighEffA = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Hea), HighEffU = gm.AssesseeSpResponses .Where(response => response.AssessorPersonId != response.AssesseePersonId) .Count(response => response.MpItemResponse == MpSpItemResponse.Heu) }, SelfStratPosition = gm.AssesseeStratResponse .Where(strat => strat.AssessorPersonId == gm.StudentId) .Select(strat => strat.StratPosition).FirstOrDefault(), PubStratResponses = gm.AssessorStratResponse.Where(strat => strat.AssesseePersonId != gm.StudentId) .Select(strat => new PubStratResponse { AssesseeId = strat.AssesseePersonId, StratPosition = strat.StratPosition }), PeersDidNotAssessMe = prundedGm.Where(peer => peer.AssessorSpResponses .Count(response => response.AssesseePersonId == gm.StudentId) == 0) .Select(peer => peer.StudentId), PeersIdidNotAssess = prundedGm.Where(peer => peer.AssesseeSpResponses .Count(response => response.AssessorPersonId == gm.StudentId) == 0) .Select(peer => peer.StudentId), PeersDidNotStratMe = prundedGm.Where(peer => peer.AssessorStratResponse .Count(strat => strat.AssesseePersonId == gm.StudentId) == 0) .Select(peer => peer.StudentId), PeersIdidNotStrat = prundedGm.Where(peer => peer.AssesseeStratResponse .Count(strat => strat.AssessorPersonId == gm.StudentId) == 0) .Select(peer => peer.StudentId) }) }).ToList(); if (!pubWgData.Any()) { return(null); } foreach (var wg in pubWgData) { //Dictionary used to keep the assessee personid with an additional dictionary to keep the //assessee strat position and the number of those position var assesseeStratDict = new Dictionary <int, Dictionary <int, int> >(); foreach (var gm in wg.PubWgMembers) { foreach (var response in gm.PubStratResponses) { Dictionary <int, int> assesseResponses; var hasAssessee = assesseeStratDict.TryGetValue(response.AssesseeId, out assesseResponses); var position = response.StratPosition > gm.SelfStratPosition ? response.StratPosition - 1 : response.StratPosition; if (!hasAssessee) { assesseeStratDict[response.AssesseeId] = new Dictionary <int, int>(); } int stratPositionCount; var hasStratPosition = assesseeStratDict[response.AssesseeId].TryGetValue(position, out stratPositionCount); if (!hasStratPosition) { assesseeStratDict[response.AssesseeId][position] = 1; } else { assesseeStratDict[response.AssesseeId][position] = stratPositionCount += 1; } } } foreach (var gm in wg.PubWgMembers) { var myResponses = assesseeStratDict[gm.StudentId]; gm.StratTable = myResponses.Select(mr => new PubWgStratTable { Position = mr.Key, Count = mr.Value }); } } return(pubWgData); }