Friday, March 22, 2019

.NET EF setup thoughts

Hi,

I'm working on a project of mine which I hadn't worked on in a couple of years (MVC 5). I'm trying to clean up the code but I'm hit with some difficulties and want to check if I'm doing this correctly.

I have a set of entities which contain my data and have quite a few links between each other (using virtual keyword for lazy loading). I have AutoMapper setup which maps the data entities towards DTOs and visa versa. Currently I have a lot of child data being either lazy loaded (virtual keyword) or eager loaded (using Include statements).

Now when this loaded data gets put into their DTOs by AutoMapper, the child data also gets put in correctly I'll often have a lot more data than needed in my views (since I use one DTO per entity, and not one per CRUD action).

I was now wondering if I should and / or could lower the data being loaded before even mapping it to the DTOs?

The thing I'm thinking about is something like the following:

List.Where(predicate).Include(predicate).Select(new object { only select fields I really need)};

Would it be possible to perform something like this and map them to a more specific DTO in my proxy layer? What kind of object would this return? Should I use the DTO object directly in the select statement? Will this enhance performance due to only loading what is needed?

I'm having a lot of performance issues with this project (compared to my .NET Core projects and was wondering if this would help.

.NET EF setup thoughts Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team