Hello, I am working with Entity Framework Code First, the environment is desktop (Windows Forms) and my query is the following.
I need to load a DataGridView with only two properties, id and description, can this select be done with linq?
The idea is to load only those two properties of the entity, not to bring me the entire entity. how can it be done via linq, using IEnumerable to fetch a list?
public IEnumerable<Proveedor> GetProveedor()
{
//TO DO....
}
It's just a query that with what Leandro offers me is already solved, I just wanted to avoid creating an Extended Provider class where I put my ProviderId, Social Reason properties With this I would be able to solve that the rest of the columns are not brought to the DGV
>>I need to load a DataGridView with only two properties id and description, can this select be done with linq?
you could define these fields in the
select
linqof course define the class with these two properties
the List <> implements
IEnumerable<>
>>isn't it necessary to make an extend class with those two properties? It's more that's what I want to avoid.
Could you apply inheritance between classes?
In EF you map the whole entity, but when you do the linq you only get back the two that are useful
You could also implement
[Entity Framework][Code First] Table Splitting
with this you can separate the table into entities by differentiating the properties.
If possible. You can do something like the following, keeping in mind that in this example I am assuming that you are going to connect to the data directly from the presentation layer (that is, from your form).
This is the class from which you want to get the data.
And with Linq you can do the following