public void GetAllCustomersWithTheirRelatedOrdersAndEmployeesUsingContext() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var contextToUse = new Context(); metaData.ContextToUse = contextToUse; // use a query which fetches Employees through orders into the customers and employee through order. // the employee entity instances in the m:n collection should be the same as the ones referenced through the order instances. var q = (from c in metaData.Customer where c.Country == "Germany" select c).With(c => c.Orders.With(o => o.Employee), c => c.EmployeeCollectionViaOrder); int count = 0; foreach (var v in q) { count++; // use object instance compare with linear search, otherwise we could get false positives as Equals and GetHashCode are tied to // the PK values of the entities, which obviously are equal. Assert.IsTrue(v.Orders.Count > 0); foreach (var o in v.Orders) { // traverse the employees in v.Employees and do an object instance compare. Has to be there var found = v.EmployeeCollectionViaOrder.Any(e => e == o.Employee); Assert.IsTrue(found); } } Assert.AreEqual(11, count); } }
public virtual async Task <IdentityUserClaimEntity> GetUserClaimAsync(long userId, string claimType, string claimValue, CancellationToken cancellationToken) { using (var da = _dbContext.GetNewAdapter()) { var metaData = new LinqMetaData(da); var result = await(from uc in metaData.IdentityUserClaim where uc.UserId == userId && uc.ClaimType == claimType && uc.ClaimValue == claimValue select uc).FirstOrDefaultAsync(cancellationToken); return(result); } }
public virtual async Task <IList <IdentityRoleClaimEntity> > GetRoleClaimsAsync(long roleId, CancellationToken cancellationToken) { using (var da = _dbContext.GetNewAdapter()) { var metaData = new LinqMetaData(da); var result = await(from uc in metaData.IdentityRoleClaim where uc.RoleId == roleId select uc).ToListAsync(cancellationToken); return(result); } }
public IEnumerable <long> GetEventIdsByHealthPlanIds(long healthPlanId, long callqueueId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); return((from fec in linqMetaData.HealthPlanFillEventCallQueue join cqc in linqMetaData.HealthPlanCallQueueCriteria on fec.CriteriaId equals cqc.Id join ea in linqMetaData.EventAccount on fec.EventId equals ea.EventId where ea.AccountId == healthPlanId && cqc.CallQueueId == callqueueId select fec.EventId).Distinct().ToArray()); } }
public List <HostPaymentTransaction> GetHostpaymentTransactions(IEnumerable <long> hostPaymentIds) { List <HostPaymentTransactionEntity> hostPaymentTransactionEntity; using (var myAdapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(myAdapter); hostPaymentTransactionEntity = linqMetaData.HostPaymentTransaction. Where(hostPaymentTransaction => hostPaymentIds.Contains(hostPaymentTransaction.HostPaymentId)). ToList(); } return(_mapper.MapMultiple(hostPaymentTransactionEntity).ToList()); }
public CorporateAccount GetByTagWithOrganization(string tag) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entity = (from a in linqMetaData.Account where a.Tag == tag select a).WithPath(path => path.Prefetch(a => a.Organization)).SingleOrDefault(); if (entity == null) { return(null); } return(Mapper.Map(entity)); } }
public bool IsCorporateAccount(long accountId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var accountid = (from a in linqMetaData.Account where a.AccountId == accountId && !a.IsHealthPlan select a.AccountId ).FirstOrDefault(); return(accountid > 0 ? true : false); } }
public IEnumerable <OrderedPair <long, string> > GetEventIdCorporateAccountNamePair(IEnumerable <long> eventIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); return((from ea in linqMetaData.EventAccount join o in linqMetaData.Organization on ea.AccountId equals o.OrganizationId where eventIds.Contains(ea.EventId) select new OrderedPair <long, string>(ea.EventId, o.Name) ).ToArray()); } }
public override async Task <IEnumerable <SalesOrderHeaderDto> > FetchGraphAsync() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = from soh in metaData.SalesOrderHeader where soh.SalesOrderId > 50000 && soh.SalesOrderId <= 51000 select soh; var toReturn = await q.ProjectToSalesOrderHeaderDto().ToListAsync(); return(toReturn); } }
public IEnumerable <EventCustomerDiagnosis> GetByEventCustomerIds(IEnumerable <long> eventCustomerIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from ecd in linqMetaData.EventCustomerDiagnosis where eventCustomerIds.Contains(ecd.EventCustomerId) select ecd).ToArray(); return(Mapper.Map <IEnumerable <EventCustomerDiagnosisEntity>, IEnumerable <EventCustomerDiagnosis> >(entities)); } }
public PhysicianMaster GetById(long id) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entity = (from pm in linqMetaData.PhysicianMaster where pm.PhysicianMasterId == id select pm).SingleOrDefault(); if (entity == null) { return(null); } return(Mapper.Map <PhysicianMasterEntity, PhysicianMaster>(entity)); } }
public IEnumerable <SurveyQuestion> GetAllQuestionsForTemplateId(long templateId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from sq in linqMetaData.SurveyQuestion join stq in linqMetaData.SurveyTemplateQuestion on sq.Id equals stq.QuestionId where stq.TemplateId == templateId select sq).ToArray(); return(Mapper.Map <IEnumerable <SurveyQuestionEntity>, IEnumerable <SurveyQuestion> >(entities)); } }
public IEnumerable <long> GetMammoEnableEventIds(IEnumerable <long> eventids) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var testIds = TestGroup.BreastCancer; var eventIdTestIdPair = (from et in linqMetaData.EventTest where eventids.Contains(et.EventId) && testIds.Contains(et.TestId) select et.EventId).ToArray(); return(eventIdTestIdPair); } }
public IEnumerable <EventPodRoomTest> GetEventPodRoomTestsByEventRoomIds(IEnumerable <long> ids) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from epr in linqMetaData.EventPodRoom join eprt in linqMetaData.EventPodRoomTest on epr.EventPodRoomId equals eprt.EventPodRoomId where ids.Contains(epr.EventPodRoomId) select eprt).ToArray(); return(Mapper.Map <IEnumerable <EventPodRoomTestEntity>, IEnumerable <EventPodRoomTest> >(entities)); } }
public virtual async Task <List <UserEntity> > GetUsersForClaimAsync(string claimType, CancellationToken cancellationToken) { using (var da = _dbContext.GetNewAdapter()) { var metaData = new LinqMetaData(da); var result = await(from uc in metaData.IdentityUserClaim where uc.ClaimType == claimType select uc.User).ToListAsync(cancellationToken); return(result); } }
public IEnumerable <HealthPlanCriteriaTeamAssignment> GetByCriteriaIds(IEnumerable <long> criteriaIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from hpcta in linqMetaData.HealthPlanCriteriaTeamAssignment where criteriaIds.Contains(hpcta.HealthPlanCriteriaId) select hpcta).ToArray(); return(Mapper.Map <IEnumerable <HealthPlanCriteriaTeamAssignmentEntity>, IEnumerable <HealthPlanCriteriaTeamAssignment> >(entities)); } }
public CorporateAccount GetByUrlSiffix(string urlSuffix) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entity = linqMetaData.Account.Where(ac => ac.CorpCode == urlSuffix).SingleOrDefault(); if (entity == null) { return(null); } return(Mapper.Map(entity)); } }
public IEnumerable <CampaignActivity> GetByCampaignIds(long[] campaignIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from cga in linqMetaData.CampaignActivity where campaignIds.Contains(cga.CampaignId) select cga); return(Mapper.Map <IEnumerable <CampaignActivityEntity>, IEnumerable <CampaignActivity> >(entities)); } }
public CorporateAccount GetByTag(string tag) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entity = (from a in linqMetaData.Account where a.Tag == tag select a).SingleOrDefault(); if (entity == null) { return(null); } return(Mapper.Map(entity)); } }
public IEnumerable <PaymentInstrument> GetByOrderId(long orderId) { // TODO: Does this need to take into account how much of a payment is applied to a given order? IEnumerable <long> paymentIds; using (var myAdapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(myAdapter); paymentIds = linqMetaData.PaymentOrder.Where(po => po.OrderId == orderId). Select(po => po.PaymentId).ToList(); } return(paymentIds.SelectMany(pid => GetByPaymentId(pid))); }
public IEnumerable <CallCenterNotes> GetCallCenterNotesByCallId(long callId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from ccn in linqMetaData.CallCenterNotes where ccn.CallId.HasValue && ccn.CallId.Value == callId select ccn).ToArray(); return(Mapper.Map <IEnumerable <CallCenterNotesEntity>, IEnumerable <CallCenterNotes> >(entities)); } }
public IEnumerable <Notification> GetFaxNotificationByNotificationTypeId(long mediumId, long notificationTypeId) { using (var adapter = _persistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = NotificationEntities(linqMetaData) .Where(n => n.NotificationTypeId == notificationTypeId && n.ServiceStatus == (int)NotificationServiceStatus.Unserviced && n.NotificationMediumId == mediumId) .ToArray(); return(_notificationMapper.MapMultiple(entities)); } }
public IEnumerable <CallQueueAssignment> GetByCallQueueId(long callQueueId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from cqa in linqMetaData.CallQueueAssignment where cqa.CallQueueId == callQueueId orderby cqa.Percentage descending select cqa).ToArray(); return(Mapper.Map <IEnumerable <CallQueueAssignmentEntity>, IEnumerable <CallQueueAssignment> >(entities)); } }
public IEnumerable <OrderedPair <long, decimal> > GetEventCustomerIdTotalPaymentPair(IEnumerable <long> eventCustomerIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); return ((from ecp in linqMetaData.EventCustomerPayment where eventCustomerIds.Contains(ecp.EventCustomerId) select new OrderedPair <long, decimal>(ecp.EventCustomerId, ecp.NetPayment) ).ToArray()); } }
public bool IsEventZipAlreadyGenerated(long eventId) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var entities = (from ez in linqMetaData.EventZip where ez.EventId == eventId select ez.ZipId); return(entities.Count() > 0); } }
public IEnumerable <string> GetHealthPlanTags() { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var tags = (from a in linqMetaData.Account where a.IsHealthPlan select a.Tag ).ToArray(); return(tags); } }
public IEnumerable <OrderedPair <long, long> > GetPreApprovedTestIdsByCustomerIds(IEnumerable <long> eventCustomerIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); return((from ecpat in linqMetaData.EventCustomerPreApprovedTest join t in linqMetaData.Test on ecpat.TestId equals t.TestId join ec in linqMetaData.EventCustomers on ecpat.EventCustomerId equals ec.EventCustomerId where eventCustomerIds.Contains(ecpat.EventCustomerId) select new OrderedPair <long, long>(ec.EventCustomerId, t.TestId)).ToArray()); } }
public IEnumerable <Campaign> GetCampaignDetails(int pageNumber, int pageSize, CampaignListModelFilter filter, out int totalRecords) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var query = (from cu in linqMetaData.Campaign select cu); if (filter != null) { if (filter.IsPublished) { query = (from cu in query where cu.IsPublished == filter.IsPublished select cu); } if (!string.IsNullOrEmpty(filter.Name)) { query = (from cu in query where cu.Name.ToLower().Contains(filter.Name.ToLower()) select cu); } if (filter.CampaignTypeId.HasValue && filter.CampaignTypeId.Value > 0) { query = (from cu in query where cu.TypeId == filter.CampaignTypeId select cu); } if (filter.CampaignModeId.HasValue && filter.CampaignModeId.Value > 0) { query = (from cu in query where cu.ModeId == filter.CampaignModeId select cu); } if (filter.StartDate.HasValue) { query = (from cu in query where cu.StartDate.Date >= filter.StartDate.Value.Date select cu); } if (filter.EndDate.HasValue) { query = (from cu in query where cu.EndDate.Date <= filter.EndDate.Value.Date select cu); } if (filter.AccountId.HasValue && filter.AccountId.Value > 0) { query = (from cu in query where cu.AccountId == filter.AccountId select cu); } } totalRecords = query.Count(); var entities = query.OrderByDescending(p => p.ModifiedOn).TakePage(pageNumber, pageSize).Select(x => x).ToArray(); return(AutoMapper.Mapper.Map <IEnumerable <CampaignEntity>, IEnumerable <Campaign> >(entities)); } }
public IEnumerable <CallQueueCustomerCallViewModel> GetCallForCallQueueCustomerList(IEnumerable <long> customerIds, IEnumerable <long> prospectCustomerIds) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetatData = new LinqMetaData(adapter); var customerCalls = (from c in linqMetatData.Calls where c.CalledCustomerId.HasValue && customerIds.Contains(c.CalledCustomerId.Value) select c).ToArray(); var callList = new List <CallQueueCustomerCallViewModel>(); if (customerCalls.Any()) { callList.AddRange(customerCalls.Select(cc => new CallQueueCustomerCallViewModel { CallId = cc.CallId, CallDateTime = cc.DateCreated, CreatedByOrgRoleUserId = cc.CreatedByOrgRoleUserId, CustomerId = cc.CalledCustomerId.Value, Status = cc.Status }).ToList()); } if (prospectCustomerIds != null && prospectCustomerIds.Any()) { var prospectCustomerCalls = (from pc in linqMetatData.ProspectCustomerCall join c in linqMetatData.Calls on pc.CallId equals c.CallId where prospectCustomerIds.Contains(pc.ProspectCustomerId) select new CallQueueCustomerCallViewModel { CallId = c.CallId, CallDateTime = c.DateCreated, CreatedByOrgRoleUserId = c.CreatedByOrgRoleUserId, ProspectCustomerId = pc.ProspectCustomerId, Status = c.Status }).ToArray(); if (prospectCustomerCalls.Any()) { prospectCustomerCalls = prospectCustomerCalls.Where(pcc => !callList.Select(cl => cl.CallId).Contains(pcc.CallId)).Select(pcc => pcc).ToArray(); if (prospectCustomerCalls.Any()) { callList.AddRange(prospectCustomerCalls); } } } return(callList); } }
public ActionResult Reset(ResetModel model) { string message; // Email address must be specified. if (!string.IsNullOrWhiteSpace(model.Email)) { // Get all accounts with that email address; check if there are any. var accounts = new LinqMetaData().User.Where(u => u.EmailAddress == model.Email); if (accounts.Any()) { // Have some accounts. Filter out all but the unrestricted ones. accounts = GetUnrestictedOnly(accounts, model.UserName, out message); if (accounts.Any()) { // Have unrestricted accounts. They will be reset. Assume there's // more than one. If more than one, we don't necessarily know the // person's name. string firstName = null; string lastName = null; if (accounts.Count() == 1) { // Only one. So get person's name. var account = accounts.First(); firstName = account.FirstName; lastName = account.LastName; } // Create restriction on each account, send email and tell user it's done. var key = CreateRestriction(accounts, model.Email, firstName != null); SendResetEmail(model.Email, key, firstName, lastName); return(RedirectToAction("ResetSuccess")); } } else { // No accounts with the specified email address. Tell user. message = Account.Invalid_EmailNotMatched; } } else { // No email address. Tell user to enter one. message = Account.Invalid_EmailNotSpecified; } ModelState.AddModelError("", message); // If we got this far, something failed, redisplay form. return(View()); }
public IEnumerable <PhysicianMaster> Search(string firstName, string lastName, string zipcode, int pageNumber, int pageSize, out int totalRecords) { using (var adapter = PersistenceLayer.GetDataAccessAdapter()) { var linqMetaData = new LinqMetaData(adapter); var query = (from pm in linqMetaData.PhysicianMaster where pm.IsActive select pm); if (!string.IsNullOrEmpty(zipcode)) { //query = (from q in query where q.PracticeZip == zipcode select q); var zipInRange = _zipcodeRepository.GetZipCodesInRadius(zipcode, 10); var zipCodesInRange = zipInRange != null?zipInRange.Select(zcir => zcir.Zip).ToList() : null; if (!(zipCodesInRange == null || zipCodesInRange.IsEmpty())) { var mapping = new FunctionMapping(this.GetType(), "IndexOf", 2, " charindex({0}, {1})"); if (linqMetaData.CustomFunctionMappings == null) { linqMetaData.CustomFunctionMappings = new FunctionMappingStore(); } linqMetaData.CustomFunctionMappings.Add(mapping); mapping = new FunctionMapping(typeof(Convert), "ToString", 1, "',' + Convert(varchar, {0}) + ','"); linqMetaData.CustomFunctionMappings.Add(mapping); string zipIdstring = "," + string.Join(",", zipCodesInRange) + ","; query = from pm in linqMetaData.PhysicianMaster where pm.IsActive && IndexOf(Convert.ToString(pm.PracticeZip), zipIdstring) > 0 select pm; } } if (!string.IsNullOrEmpty(firstName)) { query = (from q in query where q.FirstName.Contains(firstName) select q); } if (!string.IsNullOrEmpty(lastName)) { query = (from q in query where q.LastName.Contains(lastName) select q); } query = (from q in query orderby q.FirstName, q.LastName, q.PhysicianMasterId select q); totalRecords = query.Count(); var entities = query.TakePage(pageNumber, pageSize).ToList(); return(Mapper.Map <IEnumerable <PhysicianMasterEntity>, IEnumerable <PhysicianMaster> >(entities)); } }
public void Should_perform_in_transaction_with_rollback() { var service = _container.Resolve<CustomerService>(); //THIS SHOULD HAPPEN IN A TRANSACTION _facade.On(service).Invoke(a => { a.SetNameToBrodie("CHOPS"); Assert.AreEqual("Brody", a.Query.Single(b => b.CustomerId == "CHOPS").CompanyName); },false); // transaction should have rolled back - iow, there should not be any more brody var adapter = new DataAccessAdapter(); var md = new LinqMetaData(adapter); Assert.AreNotEqual("Brody", md.Customer.Single(b => b.CustomerId == "CHOPS").CompanyName); }
public void GetAllCustomersWithTheirRelatedOrders() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer where !(new[] {"FISSA", "PARIS"}.Contains(c.CustomerId)) select c).With(c => c.Orders); int count = 0; foreach (var v in q) { count++; Assert.IsTrue(v.Orders.Count > 0); } Assert.AreEqual(89, count); } }
public void GetAllCustomersWithTheirRelatedOrdersWhichAreHandledByEmployee3() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer select c).With(c => c.Orders.FilterBy(o => o.EmployeeId == 3)); int count = 0; foreach (var v in q) { count++; if (v.Orders.Count > 0) { foreach (var o in v.Orders) { Assert.AreEqual(3, o.EmployeeId); } } } Assert.AreEqual(91, count); } }
public void GetTerritoriesWithEmployeesAndCustomersOrdersInComplexPathUsingMethodCallPaths() { using (var adapter = new DataAccessAdapter()) { const bool yieldOrders = true; var metaData = new LinqMetaData(adapter); var q = (from t in metaData.Territory select t) .With(t => t.EmployeeCollectionViaEmployeeTerritory .With(GetCustomerCollectionViaOrderWithOrdersPath(yieldOrders))); int count = 0; foreach (var v in q) { count++; if (new[] {"29202", "72716", "75234", "78759"}.Contains(v.TerritoryId)) { // territory has no employees continue; } Assert.IsTrue(v.EmployeeCollectionViaEmployeeTerritory.Count > 0); foreach (var e in v.EmployeeCollectionViaEmployeeTerritory) { Assert.IsTrue(e.Orders.Count > 0); Assert.IsTrue(e.CustomerCollectionViaOrder.Count > 0); foreach (var c in e.CustomerCollectionViaOrder) { if (!(new[] {"FISSA", "PARIS"}.Contains(c.CustomerId))) { Assert.IsTrue(c.Orders.Count > 0); } } } } Assert.AreEqual(53, count); } }
public void GetTerritoriesWithEmployeesAndCustomersOrdersInComplexPathUsingMixedInlinePaths() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); Expression<Func<EmployeeEntity, object>> employeeOrdersPath = e => e.Orders; var q = (from t in metaData.Territory select t) .With(t => t.EmployeeCollectionViaEmployeeTerritory .With(employeeOrdersPath, GetCustomerCollectionViaOrderWithOrdersPath(false).First())); int count = 0; foreach (var v in q) { count++; if (new[] {"29202", "72716", "75234", "78759"}.Contains(v.TerritoryId)) { // territory has no employees continue; } Assert.IsTrue(v.EmployeeCollectionViaEmployeeTerritory.Count > 0); foreach (var e in v.EmployeeCollectionViaEmployeeTerritory) { Assert.IsTrue(e.Orders.Count > 0); Assert.IsTrue(e.CustomerCollectionViaOrder.Count > 0); foreach (var c in e.CustomerCollectionViaOrder) { if (!(new[] {"FISSA", "PARIS"}.Contains(c.CustomerId))) { Assert.IsTrue(c.Orders.Count > 0); } } } } Assert.AreEqual(53, count); } }
public void GetCustomerWithRelatedOrdersSortedByFieldAndLimit() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer where c.CustomerId == "ALFKI" select c) .With(c => c.Orders.OrderBy(o => o.Freight) .LimitTo(2)); foreach (var v in q) { Assert.IsTrue(v.Orders.Count <= 2); Assert.AreEqual("ALFKI", v.CustomerId); } } }
public void GetOrderDetailsWithOrderSortedOnCustomerRelatedToOrder() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from od in metaData.OrderDetail where od.ProductId > 10 select od).With(od => od.Order.OrderBy(o => o.Customer.Country)); int count = q.ToArray().Count(); Assert.AreEqual(1939, count); } }
public void GetOrdersWithRelatedCustomersIfCustomerStartsWithC() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from o in metaData.Order where o.EmployeeId == 3 select o).With(o => o.Customer.FilterBy(c => c.CustomerId.StartsWith("C"))); int count = 0; foreach (var v in q) { count++; if (v.CustomerId.StartsWith("C")) { Assert.IsNotNull(v.Customer); Assert.AreEqual(v.CustomerId, v.Customer.CustomerId); } else { Assert.IsNull(v.Customer); } } Assert.AreEqual(127, count); } }
public void GetSingleCustomerWithRelatedOrders() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer select c).With(c => c.Orders) .Single(c => c.CustomerId == "CHOPS"); Assert.AreEqual("CHOPS", q.CustomerId); Assert.IsTrue(q.Orders.Count > 0); } }
public void GetAllCustomersWithTheirLast2OrdersWithSubPaths() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer where !(new[] {"FISSA", "PARIS"}.Contains(c.CustomerId)) select c).With(c => c.Orders.OrderByDescending(o => o.OrderDate) .LimitTo(2) .With(o => o.OrderDetails, o => o.Employee)); int count = 0; foreach (var v in q) { count++; Assert.IsTrue((v.Orders.Count > 0) && (v.Orders.Count <= 2)); if (v.Orders.Count > 0) { foreach (var o in v.Orders) { Assert.IsTrue(o.OrderDetails.Count > 0); Assert.IsNotNull(o.Employee); } } } Assert.AreEqual(89, count); } }
public void GetAllCustomersWithTheirLast2Orders() { using (var adapter = new DataAccessAdapter()) { adapter.ParameterisedPrefetchPathThreshold = 1; var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer where !(new[] {"FISSA", "PARIS"}.Contains(c.CustomerId)) select c).With(c => c.Orders.OrderByDescending(o => o.OrderDate) .LimitTo(2)); int count = 0; foreach (var v in q) { count++; Assert.IsTrue((v.Orders.Count > 0) && (v.Orders.Count <= 2)); } Assert.AreEqual(89, count); } }
public void GetAllCustomersFromGermanyWithTheirOrdersAndRelatedEmployeeAndOrderDetailsWithExcludedFields() { using (var adapter = new DataAccessAdapter()) { var metaData = new LinqMetaData(adapter); var q = (from c in metaData.Customer where c.Country == "Germany" select c).With(c => c.Orders.With(o => o.OrderDetails, o => o.Employee.Exclude(e => e.Photo, e => e.Notes))); int count = 0; foreach (var v in q) { count++; Assert.IsTrue(v.Orders.Count > 0); foreach (var o in v.Orders) { Assert.IsNotNull(o.Employee); Assert.IsTrue(o.OrderDetails.Count > 0); } } Assert.AreEqual(11, count); } }