Entity to datagridview with prefetch

Posts   
 
    
OSSistemes
User
Posts: 23
Joined: 20-Nov-2019
# Posted on: 20-Sep-2021 04:54:48   

Hi all,

I'm tried to bind a entity to datagrid with a prefetch data, I check the prefetched data and its ok, but I don't no know to put info in column using datapropertyname here my code:

var orders = new TiquetsCollection();
var prefetchPath = new PrefetchPath(EntityType.TiquetsEntity);
prefetchPath.Add(TiquetsEntity.PrefetchPathCustomer);
rr.GetMulti(TiquetsFields.IdTiquet.Equal(1), prefetchPath);

dgv_orders.DataSource = orders;
dgv_orders.Columns[0].DataPropertyName = IdTiquet;
dgv_orders.Columns[1].DataPropertyName = Customer.Name;  //here my problem, the name is not showed on datagridview

Its possible do that without using typedview?

Thanks team!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 20-Sep-2021 09:04:50   

What is 'Customer.Name' ? If you have to set it to a string, why not use nameof(CustomerEntity.Name) ?

Frans Bouma | Lead developer LLBLGen Pro
OSSistemes
User
Posts: 23
Joined: 20-Nov-2019
# Posted on: 20-Sep-2021 09:23:26   

Otis wrote:

What is 'Customer.Name' ? If you have to set it to a string, why not use nameof(CustomerEntity.Name) ?

dgv_orders.Columns[0].DataPropertyName = "IdTiquet";
dgv_orders.Columns[1].DataPropertyName = "Customer.Name";

Customer is an Entity and Name is a field of this.

edit: I put "dgv_orders.Columns[1].DataPropertyName = nameof(Customer.Name);" with same result, no value showed in datagrid

What can I do?

Many thanks

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 20-Sep-2021 21:07:08   

As far as I remember WinForms DataGrid can't bind to a nested property.

However you can expose the related entity property on the main entity. i.e. create a custom property inside the main entity that returns the related entity property (hint: first check if related entity is not null)

Do the above inside a #user_Code_region or better in a partial class file so it's won't get overwritten in the next code generation.

OSSistemes
User
Posts: 23
Joined: 20-Nov-2019
# Posted on: 21-Sep-2021 16:32:19   

Walaa wrote:

As far as I remember WinForms DataGrid can't bind to a nested property.

However you can expose the related entity property on the main entity. i.e. create a custom property inside the main entity that returns the related entity property (hint: first check if related entity is not null)

Do the above inside a #user_Code_region or better in a partial class file so it's won't get overwritten in the next code generation.

Hi finally I do that!!

Works ok, thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 22-Sep-2021 09:28:33   

The designer has support for this btw simple_smile Field mapped onto related field in the entity editor. You can define your fields there and they're automatically generated (and cleaned up when the model changes).

Frans Bouma | Lead developer LLBLGen Pro