Entity Framework Feature Suggestions

Decouple entity creation in EF and support entities without default constructors and publically settable properties

EF should decouple the implementation of the entity objects from the mapping functionalities. The EF team could provide the current entity creation as a default variant which can be attached to the mapper. The developer has the option to provide it's own data transfer object layer. Therefore we need to abstract the entities through interface usage an a generic naming schema (dot notation of an object model like Person.Name). So the EF would be much more flexible to use.

Note by Diego Vega: I am merging this idea with a few other ideas that are approximately equivalent but extend in other directions:

- On one hand we could support materializing objects invoking constructors with parameters and non-publically settable properties. Another way to do it (popular in among users of other O/RMs) would be to support materializing to private fields. In addition, we could support registering factory methods or some other resolution mechanism like plugging in an IoC container.

- On one hand, support for materialization of objects with constructors with parameters could be transparent, e.g. the query db.Customers doesn't need to specify how each customer needs to be constructed. It just specifies that customers can be queried using this property. On the other hand, we could also allow explicitly constructing an object with a constructor with parameters in the outmost projection: db.Customers.Select(c => new ListItem(c.Id, c.Name)).

287 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Mike FlaskoMike Flasko shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    Mark SeemannMark Seemann shared a merged idea: Support for POCO Entities without default constructors and publically settable properties  ·   · 
    Diego VegaAdminDiego Vega (Development Lead, DataFx) responded  · 

    Reverting status from “under review” to “no status” since we aren’t currently working on this. We will still consider it for future releases.

    10 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base