I have created a method in C#.net 4.0 which returns a dynamic type:
public dynamic GetEntertainmentDetails(int entertainmentId)
{
dynamic result = from PE in entities.ProductEntertainments
join PM in entities.ProductModels on PE.ProductModelID equals PM.ProductModelID
join PMA in entities.ProductMasters on PM.ProductUID equals PMA.ProductUID
join PMF in entities.ProductManufactorers on PMA.ManufactorerID equals PMF.ManufactorerID
where PE.EntertainmentID == entertainmentId
select new { PE.EntertainmentID, PMF.ManufactorerID, PMA.ProductUID, PM.ProductModelID, PE.CDPlayer, PE.CDChanger, PE.DVDPlayer, PE.Radio, PE.AudioSystemRemoteControl, PE.SpeakersFront, PE.SpeakersRear };
return result;
}
I want to use the results in a method which goes like this:
private void DisplayRecord()
{
dynamic item = dbContext.GetEntertainmentDetails(entertainmentId);
this.cmbManufacturer.SelectedValue = item.ManufactorerID;
this.cmbProducts.SelectedValue = item.ProductUID;
this.cmbVariant.SelectedValue = item.ProductModelID;
if (item.CDPlayer == true)
this.cdPlayerYes.IsChecked = true;
else
this.cdPlayerNo.IsChecked = true;
}
But value returned is not being set in cmbManufactorer or any other control. I tested that dyanmic item has values but not sure why are they not being set.
Is it the right way to handle it or am I doing wrong here ?
Update: I am using this code in a WPF application. SelectedValue property can be get/set there for dropdowns.