Ideally, I’d hit the database exactly once for only the data I need, and nothing more. I use LazyLoading, if you don´t you have to explicitly load navigationProperties/Collections. Ef select to new dto with icollections plus This is what I often see people create stored procedures for building up the exact resultset you need at the database level, only getting what we need. ![]() That is it can convert a small but useful number of LINQ collection commands into SQL commands. For new cities, we map from DTO to Entity (AutoMapper creates a new instance) and add it to countrys collection. I have a similar object-graph an this works fine for me. As well as accessing columns in one-to-one relationships there is another feature that EF and ExpressMapper’s flattening can provide for one-to-many relationships. ![]() Equalit圜omparison((p, dto) => p.Id = dto.Id) Var config = new MapperConfiguration(cfg =>Ĭfg.UseEntityFrameworkCoreModel(services) Ĭfg.AddProfile(new YourProfile()) // (MemberList.Destination) This is how I configured AutoMapper in Startup.cs with an extension method, so that I´m able to call services.AddAutoMapper() without the whole configuration-code: public static IServiceCollection AddAutoMapper(this IServiceCollection services) Var customer = (e => e.Id = id) Ĭontext.Entry(entity).CurrentValues.SetValues(updated) Īnd secound you should take advantage of . In general Linq to Enitities wont accept any method inside select section - because you working with the genreated by Entity Framework query not the data, only after calling ToList() or ToDictionary() you actually have the data from the database. Public IActionResult Patch(int id, JsonPatchDocument patchDocument) The main DTO class is something like this ( simplified of course): public class CustomerDto ")] I am trying to use (POST/PUT) a DTO object with a collection of child objects from JavaScript to an ASP.NET Core (Web API) with an EF Core context as my data source.
0 Comments
Leave a Reply. |