This is a migrated thread and some comments may be shown as answers.

[Solved] Displaying foreign key value with entity framework?

3 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
pantarhei
Top achievements
Rank 1
pantarhei asked on 18 Aug 2009, 10:25 PM
Hello,
i'm just playing around with Silverlight and Telerik controls. for now i have a RIA Service Demo Application. at the moment
i can't figure out how to bind my fk value to the grid.

the grid itself is bound to a service that receives all cars.

//Displaying all cars in the grid 
CarContext ctx = new CarContext(); 
 
carGrid.ItemsSource = ctx.Cars; 
ctx.Load(ctx.GetCarsQuery()); 

displaying the carmakers name works in code if i manually create a GridViewComboBoxColumn an bind it to the
data receiving from a seperate service.

//Getting carmakers from a seperate carMakerService 
GridViewComboBoxColumn carMakerSelect = new GridViewComboBoxColumn(); 
carMakerSelect.HeaderText = "Carmaker"
carMakerSelect.DataMemberBinding = new Binding("carmaker_id"); 
carMakerSelect.DisplayMemberPath = "name"
carMakerSelect.SelectedValueMemberPath = "id"
 
carMakerSelect.ItemsSource = carMakerContext.Carmakers; 
carMakerContext.Load(herstellerDal.GetCarMakerQuery()); 
 
this.carGrid.Columns.Add(carMakerSelect); 
 
is this the only way to connect a fk to the grid if i only like to display the fk's value? can this be done in xaml too?
 i think i'm missing something in general and it's not 100% telerik datagrid related. but perhaps you can show me the right direction. :)

regards

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Aug 2009, 11:20 AM

Hello pantarhei,

I am not sure I get the problem right but all of the following properties can be set directly in XAML to the relevant ComboBoxColumn:

HeaderText
DataMemberBinding
DisplayMemberPath
SelectedValueMemberPath
ItemsSource

Something like :

<telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False">  
            <telerik:RadGridView.Columns> 
                <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryID}" DisplayMemberPath="Name" SelectedValueMemberPath="ID" ...


Regarding the ItemsSource - you may provide it trough a static resource in the XAML of the page.

Kind regards,

Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
pantarhei
Top achievements
Rank 1
answered on 19 Aug 2009, 03:48 PM
Hello Pavel,

thanks for your reply. My problem was as i supposed not really Telerik specific. i forgot to set the [Include] attribute in my metadata.
result was that the carmakers have never been serialised and thus i wasn't able to display the value in the grid. i'm just at the beginning stage.

i can now display the carmakers name with the following code. 
//Query on my entity model 
return this.Context.Cars.Include("Carmaker"); 
 
//Binding a Master-Value to a column 
<telerikGridView:GridViewDataColumn   
  HeaderText="Horsepower"  
  DataMemberBinding="{Binding horsepower}" />  
 
//Binding Detail-Value to a column 
<telerikGridView:GridViewDataColumn   
  HeaderText="Carmaker"  
  DataMemberBinding="{Binding Carmaker.name}" />  
 

now i have another question regarding this. the "Carmaker" column isn't showing the filter symbol. the Horsepower column is displaying it. how to filter "Detail" column?
0
Pavel Pavlov
Telerik team
answered on 20 Aug 2009, 01:09 PM
Hello pantarhei,

The first thing I can think of is  that  the filtering icon would not display if the underlying business object does not implement IComparable or IEquatable.

Let me know if that is not the case .


Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
pantarhei
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
pantarhei
Top achievements
Rank 1
Share this question
or