Reputation: 598
I am trying to JOIN with LINQ & Lambda. But Getting an error stating Cannot Implicitly convert anonymoustype#1 to BRAND_NAME_MAP_ID. I am fairly new to Lambdas and stuck here.
public BRAND_NAME_MAP_MASTER GetBrandNameBrandNameMapID(int BrandNameMapID)
{
PFC_BRAND_NAME_MAP_MASTER objBrandNameMap = Db.PFC_BRAND_NAME_MAP_MASTERs
.Join(SIRDC.INGREDIENT_BRAND_NAME_MAPs,
a => a.BRAND_NAME_MAP_ID,
b => b.BRAND_NAME_MAP_ID,
(a, b) => new {a, b})
.Where(x => x.a.BRAND_NAME_MAP_ID == PFCBrandNameMapID)
.FirstOrDefault(); //Getting error here
return objPFCBrandNameMap;
}
Upvotes: 1
Views: 107
Reputation: 119156
Your query is returning an anonymous type containing two properties, a
is a PFC_BRAND_NAME_MAP_MASTER
and b
is a INGREDIENT_BRAND_NAME_MAP
. It looks like you only need the first property so just add a Select
to get at it:
PFC_BRAND_NAME_MAP_MASTER objBrandNameMap = Db.PFC_BRAND_NAME_MAP_MASTERs
.Join(SIRDC.INGREDIENT_BRAND_NAME_MAPs,
a => a.BRAND_NAME_MAP_ID,
b => b.BRAND_NAME_MAP_ID,
(a, b) => new {a, b})
.Where(x => x.a.BRAND_NAME_MAP_ID == PFCBrandNameMapID)
.Select(x => x.a) /Add this line
.FirstOrDefault();
Upvotes: 4