Compare 2 entity items RRS feed

  • Question

  • User375833105 posted

    Not sure how to subscribe this, but I need to compare 2 items in a where clause, but 1 that comes from another join

    I placed a comment after the where clause and after the join that the data item come from. Can someone help me? this must be possible right?

                DataBundle = _context.DataTemplates.Join(_context.DataItems, DataTemplates => DataTemplates.Id, DataItems => DataItems.DataTemplateId, (DataTemplates, DataItems) => new { DataTemplates, DataItems })
                                                              .Join(_context.DataTemplateUploads, DataItemFiles => DataItemFiles.DataTemplateUploadId, DataTemplateUploads => DataTemplateUploads.Id, (DataItemFiles, DataTemplateUploads) => new { DataItemFiles, DataTemplateUploads }),
                                                   x => x.DataItems.Id, x => x.DataItemFiles.DataItemId, (x, DataItemFiles) => new { x.DataItems, x.DataTemplates, DataItemFiles })
                                                              .Join(_context.DataTemplateFields, DataItemResources => DataItemResources.DataTemplateFieldId, DataTemplateFields => DataTemplateFields.Id, (DataItemResources, DataTemplateFields) => new { DataItemResources, DataTemplateFields }) //Here comes the DataTemplateFields.LinkedToDataTemplateId
                                                                         .Join(_context.DataTemplates, DataItems => DataItems.DataTemplateId, DataTemplates => DataTemplates.Id, (DataItems, DataTemplates) => new { DataItems, DataTemplates }).Where(x => x.DataTemplates.Id == HERE),//Want to compare DataTemplates.Id with DataTemplateFields.LinkedToDataTemplateId
                                                              x => x.DataItemResources.Text, y => y.DataItems.Id.ToString(), (x, DataItems) => new { x.DataItemResources, x.DataTemplateFields, DataItems }),
                                                   x => x.DataItems.Id, x => x.DataItemResources.DataItemId, (x, DataItemResources) => new { x.DataItems, x.DataTemplates, x.DataItemFiles, DataItemResources })
                                                   .Where(x => x.DataTemplates.DetailPage == true)
                                                   .Where(x => x.DataTemplates.CallName == CallName)
                                                   .Where(x => x.DataItems.WebsiteLanguageId == WebsiteLanguageId)
                                                   .Where(x => x.DataItems.Active == true)
                                                   .Select(x => new DataBundle()
                                                       DataItemFiles = x.DataItemFiles.Select(y => y.DataItemFiles),
                                                       DataItemResources = x.DataItemResources.Select(y => y.DataItemResources),
                                                       DataItem = x.DataItems,
                                                       DataTemplateFields = x.DataItemResources.Select(y => y.DataTemplateFields),
                                                       DataTemplate = x.DataTemplates,
                                                       DataTemplateUploads = x.DataItemFiles.Select(y => y.DataTemplateUploads),
                                                       LinkedToDataTemplate = null,
                                                       LinkedToDataItems = x.DataItemResources.Select(y => y.DataItems.FirstOrDefault().DataItems)
                                                   .FirstOrDefault(x => x.DataItem.PageUrl == Url);

    Wednesday, April 19, 2017 9:20 PM

All replies

  • User-1838255255 posted

    Hi devo2017,

    According to your description, I am not clear your issue, I think you want to get the data form two tables with join, You could refer to the following code:   

    var innerJoinQuery =
                    from category in categories
                    join prod in products on category.ID equals prod.CategoryID
                    select new { ProductName = prod.Name, Category = category.Name };

    join clause (C# Reference):


    If my understand is wrong, please describe your issue, this will better help you.

    Best regards,

    Eric Du

    Thursday, April 20, 2017 10:51 AM
  • User375833105 posted

    No that is not what I mean. I have a groupjoin on a join and on that groupjoin another join. That one works, but I want to add a where clause on the join that is on the groupjoin (see comments in the code). In that where clause I want to compare a collumn with a column from the join that is before the groupjoin.

    Do you understand that? it's a bit hard to explain

    So far I know it must be possible. I work with entities for a month now, before that I always used normal queries. So i'm really new with this

    Thursday, April 20, 2017 1:11 PM
  • User2053451246 posted

    So far I know it must be possible. I work with entities for a month now, before that I always used normal queries. So i'm really new with this
    If you are familiar with doing this in "normal" queries, write that code, get it working the way it's supposed to, and then ask someone to translate it to Linq for you.

    Thursday, April 20, 2017 1:51 PM
  • User375833105 posted

    No I don't know how to write this in normal queries. Also never used groupjoin in a normal query. Before this I only wrote easy join / left join queries. This one is more complex

    Thursday, April 20, 2017 2:09 PM