0

I have a question about the linq expression:

I do a IQueryable in a class/entity from my EDMX.

On each class I would like convert the potential class associated (Address, Contact) to another class (EntityLight).

When I query my class, I found in the parameters my differents class (Address and Contact).

Each one are MemberAccess when I get these with PropertyOrField and I would like convert/replace each one to an EntityLight and retrieve the data from Address and Contact in tha EntityLight on the same fields: Id, Name.

It's possible? If it's possible how? Thanks a lot

Sample :
public class House
{
    public int Id { get; set; }
    public Address Address { get; set; }
    public Contact Owner { get; set; }
}       

public class Address
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
}       

public class Contact
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}       

public class EntityLight
{
    public int Id { get; set; }
    public string Name { get; set; }
}       
Rabbiwan
  • 1
  • 1
  • Can't you just use AutoMapper for this? You seem to be reinventing it. – Gert Arnold Jan 27 '18 at 23:21
  • hello, I think it's not possible because it's use after the IQueryable to map the result to another model like viewmodel. The objectif it's to generate a SQL query more short to not retrieve all the fields from the associated tables to increase the performance and retrieve only the adapted datas – Rabbiwan Jan 28 '18 at 09:44
  • That's what AutoMapper used to be. That's a long time ago. Look at [`ProjectTo()`](http://automapper.readthedocs.io/en/latest/Queryable-Extensions.html), or [this](https://stackoverflow.com/a/12365931/861716). – Gert Arnold Jan 28 '18 at 09:50
  • I will check this solution but the objectif it's to modify dynamicaly the IQueryable with linq expression – Rabbiwan Jan 28 '18 at 11:47

0 Answers0