How do you get a web API odatamodelbuilder to work with EF fluent API mappings

前端 未结 1 1338
南笙
南笙 2021-02-08 07:36

I have created a fairly simply domain model using pocos. I have mapped these to an EF DB context using EntityTypeConfiguration classes. This al

相关标签:
1条回答
  • 2021-02-08 08:02

    Two things:

    1. I have read multiple sources now that ward against using lazy loading and serialization; which is basically what OData is; (It even uses the system.runtime.serialization.datacontract and datamember attributes)

    2. I have had more success in explicitly loading from context, and defining navigation properties in the modelbuilder for dbContext. I understand you are looking at customized nav properties, but I am fairly sure these are overriden methods useful for the ODataModelBuilder class (that does not assume much and needs less Entity Framework to work). Where you mentioned using EF already, I imagine that is the direction you will work, and if you do not need to alias your model names, you add an entry for each Set, using convention naming.

      EntitySet("routePrefixName")

    in building the EdmModel, and it wires up the relationships you made using Fluent previously. If you do have to add extraneous items to the underlying model, you should define each class as an EntityType<>(), only setting the key. EdmBuilder can use mild properties and key association to attach to the EF model in the ODataConventionModelBuilder.

    I have wrestled and sought for some time, and there does not seem to be a wealth of information on .Net OData v4 floating around, probably due to the whole force datetimeoffset issue.

    Hope that helps somewhat

    0 讨论(0)
提交回复
热议问题