var ID, x,y
switch(ItemTypeNo)
{
case ItemType.A :
ID = from s in cntx.Tablo1
break;
case ItemType.B :
ID = from s in cntx.Tablo2
break;
case ItemType.C :
ID = from s in cntx.Tablo3
break;
}
var ID, x,y switch(ItemTypeNo) { case ItemType.A : ID = from s in cntx.Tablo1
Share
You can only use
varfor inline initialization, which that isn’t. You would need to typeIDappropriately, and sincevarhas a single type that would only work ifTablo1,Tablo2andTablo3are the same type (which seems unlikely).What is it you need to do here?
There is a scenario that works here; when selecting a common type from each; let’s assume thay all have an
intprimary key:However, in the general case… not so much. You could type
IDas the non-genericIQueryable, but to be honest that doesn’t let you do very many interesting things. Anddynamicdoesn’t play nicely with LINQ (and even if it did, it would be a hack here).