EF Core related data causing error in SfGrid

The grid fails to initialize when creating a column as such:
               <GridColumn Field=@nameof(User.Employer.Name) HeaderText="Company" TextAlign="TextAlign.Left" Width="100"></GridColumn>

the data is loaded as shown:
_users = userDb.Users.Where(u => 1 == 1).Include(c => c.Employer).ToList();

the c.Employer is defined in the User class as:
public Company Employer { get; set; }

When I debug and view the _users variable it is full of data for the Employer but the grid does not like it.

Thoughts?

Thanks Richard

3 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team May 21, 2021 09:03 AM UTC

Hi richard, 
 
Greetings from Syncfusion support. 
 
We suggest you to refer to the below documentation for more details regarding binding Complex data column to Grid. 

Please get back to us if you need further assistance.  

Regards, 
Renjith R 




RR Richard Rooks May 21, 2021 12:01 PM UTC

<GridForeignColumn Field=@nameof(User.CompanyId) HeaderText="Company" ForeignKeyValue="Name" ForeignKeyField="Id" ForeignDataSource="@_companies" Width="150"></GridForeignColumn>

That did the trick. Thanks. It would also be helpful if there was a reference to this when one wants to use EF Include statements so that your users don't get frustrated that the grid cannot use user.comapny.name, which to me would be an intuitive way for it to work.

Richard

Marked as answer

RS Renjith Singh Rajendran Syncfusion Team May 24, 2021 12:02 PM UTC

Hi richard, 

Thanks for your update. We are glad to hear that your requirement is achieved.  

We would like to inform you that we have already documented the ForeignKey column feature topic in Grid. Please refer the below documentation for more details, 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon