logo
down
shadow

LINQ Join with same Name on different tables


LINQ Join with same Name on different tables

By : tosa
Date : November 19 2020, 03:59 PM
wish help you to fix your issue I'm having trouble when joining 2 tables, The issue is on the line , Try this:-
code :
  from o in OrderSet
  join opr in OrderProductSet on o.Id equals opr.OrderId.Id
  join pri in ProductPricingSet on 
   new { BusinessUnitId = o.BusinessUnitId.Id, ProductNameId = opr.ProductNameId.Id}     
   equals new { BusinessUnitId = pri.BusinessUnitId.Id, ProductNameId =  pri.ProductId.Id}
  where o.Name.Equals("OE-000004")
  select new 
           {
              o.name,
              opr.ProductName,
              opr.Quantity,
              pri.SlipDiscount,
              pri.FinalPrice
          }


Share : facebook icon twitter icon
Select All columns for all tables in join + linq join

Select All columns for all tables in join + linq join


By : user1543964
Date : March 29 2020, 07:55 AM
around this issue While you cant expand them to columns, you can simply return the entities. Eg:
code :
select new { CTLJCRJOB, CTLRFDSTM }
LINQ to Entities, join two tables, then group and take sums of columns from both tables

LINQ to Entities, join two tables, then group and take sums of columns from both tables


By : bjpierson24
Date : March 29 2020, 07:55 AM
should help you out the transaction variable is out of scope. If you include it in you grouped result then you can use it.
change you group by clause to:
code :
group new
        {
            target,
            transaction
        }
        by new
        {
            target.ProductGroupID,
            target.StateID,
            target.Year
        } into grouped
select new
        {
            TargetL1 = grouped.Sum(groupedThing => groupedThing.target.Level1_Target,
            ActualL1 = grouped.Sum(trans => groupedThing.transaction.Level1_Total)
        }).SingleOrDefault();
How to use the group join result to join another tables using LINQ?

How to use the group join result to join another tables using LINQ?


By : TomHoover
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I am not able to use the result of group join and then further applying the join with other tables. , You need something like this:
code :
var groups = context.MortgageLoanStatusAndTrackingNotes
    .GroupBy(x => x.MortgageTrackingMortgageApplicationId)
    .Select(g => new 
    {
        MortgageTrackingMortgageApplicationId = g.Key,
        MaxDate = g.Max(date => date.MortgageTrackingDate)
    });

var result = context.MortgageApplications
    .Join(context.Applicants,
        m => m.MortgageApplicationId,
        a => a.MortgageApplicationId,
        (m, a) => new 
        {
            MortgageApplication = m,
            Applicant = a
        })
    .Join(context.SubjectProperties,
        x => x.MortgageApplication.MortgageApplicationId,
        sp => sp.PropertyMortgageApplicationId,
        (x, sp) => new
        {
            MortgageApplication = x.MortgageApplication ,
            Applicant = x.Applicant,
            SubjectProperty = sp
        })
    .Join(context.MortgageConditionsCommitments,
        x => x.MortgageApplication.MortgageApplicationId,
        cc => cc.MortgageApplicationId,
        (x, cc) => new
        {
            MortgageApplication = x.MortgageApplication ,
            Applicant = x.Applicant,
            SubjectProperty = x.SubjectProperty,
            MortgageConditionsCommitment = cc
        })
    .Join(context.MortgageLoanStatusAndTrackingNotes,
        x => x.MortgageApplication.MortgageApplicationId,
        t => t.MortgageTrackingMortgageApplicationId,
        (x, t) => new
        {
            MortgageApplication = x.MortgageApplication ,
            Applicant = x.Applicant,
            SubjectProperty = x.SubjectProperty,
            MortgageConditionsCommitment = x.MortgageConditionsCommitment,
            MortgageLoanStatusAndTrackingNotes = t
        })
    .Join(groups,
        x => x.MortgageApplication.MortgageApplicationId,
        g => g.MortgageApplicationId,
        (x, g) => new
        {
            MortgageApplication = x.MortgageApplication ,
            Applicant = x.Applicant,
            SubjectProperty = x.SubjectProperty,
            MortgageConditionsCommitment = x.MortgageConditionsCommitment,
            MortgageLoanStatusAndTrackingNotes = t,
            MortgageLoanStatusGroup = g
        });
join multiple tables using linq query and orderby the tables

join multiple tables using linq query and orderby the tables


By : JCP
Date : March 29 2020, 07:55 AM
this will help you can not see the emp variable because it has defined after line you want to refer that, you need to define emp before this line:
code :
join ep in _db.EmployerPlans on emp.PlanId equals ep.EmployerPlanId
return (from job in _db.Jobs 
        join employerregdetails in _db.EmployerRegistrationDetails 
            on job.OrganizationId equals employerregdetails.EmployerId into e
        from emp in e.DefaultIfEmpty()
        join ep in _db.EmployerPlans on emp.PlanId equals ep.EmployerPlanId
How to join 3 tables based on ID using LINQ SQL join? C# MVC (.NET Core 2.0)

How to join 3 tables based on ID using LINQ SQL join? C# MVC (.NET Core 2.0)


By : user7504740
Date : March 29 2020, 07:55 AM
this one helps. I have 3 tables/Entities called Person, PersonPhone and EmailAddress. All tables ID using the same ID called BusinessEntityID. "BusinessEntity" is also a table.
code :
public IActionResult Index()
{
    var vm = from p in db.Person
             where p.BusinessEntityId == 1
             select new PersonIndexViewModel
             {
                 Person = p,
                 PersonPhone = p.PersonPhone.FirstOrDefault(),
                 EmailAddress = p.EmailAddress.FirstOrDefault()
             };


    return View(vm.FirstOrDefault());
}
Related Posts Related Posts :
  • Parsing string with nested separators
  • How to invoke a DLL method from PowerShell 1.0
  • Starting Web Api 2 with OWIN
  • display a string with multiple lines in TextBox
  • Is it possible to programmatically get a shared Dropbox link without sending the user to the dropbox login page?
  • HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\TimeZoneKeyName corrupt?
  • Performance cost of creating array of constants as function argument
  • SQL Server rowversion and order
  • Type.GetType returns null when called via COM interop
  • Is the Microsoft.Practices.EnterpriseLibrary.Validation outdated?
  • .net Bitmap changes color of image
  • vb.net reading text file ,split to random range
  • Programmatically share a dropbox link in .net without having user login to Dropbox
  • bootstrapper fails to install .Net Framework 4.0
  • Why would signing credentials from a RSA-SHA512 X509Certificate2 appear to be RSA-SHA256?
  • Using .NET Class as the DataSource with SSRS RDLC
  • Choosing SQL Server version for new project
  • WCF FileNotFoundException
  • Fullcalendar ignoring all options on initialization?
  • Freebase oAuth2 Bad Request(400) .Net
  • Why does InlineCollection not offer an Indexer (without casting)?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org