0

I have 2 records in tblMaterials and zero record in tblMaterialTenderGroups
But when I fetch the data to gridview it shows me the two records, and the join doesn't work

    public List<tblMaterial> ShowPresentMaterialInGroup()
    {
        List<tblMaterial> q = (from i in dbconnect.tblMaterials.AsEnumerable()
                               join b in dbconnect.tblMaterialTenderGroups on i.materialId equals  b.materialId
                               where b.MaterialGroupId == _materialGroupId
                               select new tblMaterial()
                               {
                                   existAmout = i.existAmout,
                                   materialId = i.materialId,
                                   name = i.name,
                                   needAmount = i.needAmount,
                                   requestAmount = i.requestAmount,
                                   unit = i.unit,
                                   requestId = i.requestId
                               }).ToList();
        return q;
    } 
Microsoft DN
  • 9,706
  • 10
  • 51
  • 71

1 Answers1

1

Can you please try this

List<tblMaterial> q = from i in dbconnect.tblMaterials
            join b in dbconnect.tblMaterialTenderGroups on i.materialId equals  b.materialId 
            select new { existAmout = i.existAmout,
                         materialId = i.materialId,
                         name = i.name,
                         needAmount = i.needAmount,
                         requestAmount = i.requestAmount,
                         unit = i.unit,
                         requestId = i.requestId}.ToList();

May be using returning the two records..
I read something here

Using AsEnumerable will break off the query and do the "outside part" as linq-to-objects rather than Linq-to-SQL. Effectively, you're running a "select * from ..." for both your tables and then doing the joins, where clause filter, ordering, and projection client-side.

Community
  • 1
  • 1
Microsoft DN
  • 9,706
  • 10
  • 51
  • 71