简体   繁体   English

实体框架WebAPI:代码首先正确返回json,数据库首先仅返回第一个对象和其他对象的引用

[英]Entity Framework WebAPI: Code first returns json correctly, DB first only returns first object and references for others

i am moving a Code first EF project to a DB first project, cause we need to add our project to an existing DB and use some of the existing tables. 我将代码优先EF项目移至数据库优先项目,因为我们需要将我们的项目添加到现有数据库并使用一些现有表。

when i run the CodeFirst project it returns the correct JSON: 当我运行CodeFirst项目时,它返回正确的JSON:

correctJson

, but when i do the same on the DB first project it only returns the first object, and returns $refs for all the other objects. ,但是当我在DB第一个项目上执行相同操作时,它仅返回第一个对象,并为所有其他对象返回$ refs。

badJson

You will need to make use of DTO's to transfer your data from your web api to the client application. 您将需要使用DTO将数据从Web api传输到客户端应用程序。

Those references are proxies for entity framework, to lazyload these but they don't get serialized in json. 这些引用是实体框架的代理,可以延迟加载它们,但不会在json中序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架:对象首先返回一个空列表,但突然列表被正确填充 - Entity Framework: object returns with an empty list at first, but then suddenly the list is populated correctly 实体框架代码第一个对象引用多个对象 - Entity framework code first object references multiple objects 子对象未保存到数据库中,先使用实体​​框架代码 - Child object not saving into the DB, using Entity Framework Code First 实体框架代码第一个DB错误 - Entity Framework Code First DB error 首先是数据库表子集的实体框架代码 - Entity framework code first for the subset of DB tables 从实体框架代码优先到数据库优先的错误 - Error Going from Entity Framework Code First to DB First EF Code First DbContext仅返回集合的第一个元素的封装实体 - EF Code First DbContext returns encapsulated entity only for first element of collection 带有实体框架的WebAPI,代码优先:未生成插入对象的正确ID - WebAPI with Entity Framework, Code First: Doesn't generate correct Id of inserted object object 实例化上的实体框架代码优先回调 - Entity Framework Code First callback on object instantiation 实体框架代码首先用于具有属性集合的对象 - Entity Framework code first for object with collection of properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM