I have 2 tables that has a 1-1 relationship I am attempting to use the .Include() for LINQ to try to pass a child table entity to a property so that I can bind a child table field to a grid, along with fields from the parent table. Originally it works fine like this and I'm able to bind to the grid but only get results from the BUGroupBuildings table. I also need to bind to a field in the vwBuisnessUnits table.
public IQueryable<BUGroupBuilding> GetBusinessUnitsBasedOnGroupID(int i)
{
var result = from d in this.ObjectContext.BUGroupBuildings
join b in this.ObjectContext.vwBusinessUnits on d.BU equals b.BU
where d.BUGroupID == i
orderby d.BU ascending
select d;
return result;
}
When I switch over to use the Include to bring back child table fields, I get an error
public IQueryable<BUGroupBuilding> GetBusinessUnitsBasedOnGroupID(int i)
{
var result = from d in this.ObjectContext.BUGroupBuildings
.Include("vwBuisnessUnits")
select d;
result = result.Where(w => w.BUGroupID == i).OrderBy(o => o.vwBusinessUnit.BU);
return result;
}
ERROR:
Load operation failed for query 'GetBusinessUnitsBasedOnGroupID'. A specified Include path is not valid. The EntityType 'EQUITYDWModel.BUGroupBuilding' does not declare a navigation property with the name 'vwBuisnessUnits'
Here's my entity
I've added the necessary [Include] in the metadata.
[MetadataTypeAttribute(typeof(BUGroupBuilding.BUGroupBuildingMetadata))]
public partial class BUGroupBuilding
{
internal sealed class BUGroupBuildingMetadata
{
// Metadata classes are not meant to be instantiated.
private BUGroupBuildingMetadata()
{
}
public string BU { get; set; }
[Include]
public BUGroup BUGroup { get; set; }
public int BUGroupBuildingsID { get; set; }
public Nullable<int> BUGroupID { get; set; }
[Include]
public vwBusinessUnit vwBusinessUnit { get; set; }
}
}