ef6 linq方法为查询中的嵌套条目返回$ ref

时间:2019-01-31 21:06:55

标签: linq entity-framework-6 asp.net-web-api2

当我在提琴手中监视结果时,我的EF6的linq方法系统返回$ ref。如果我在webapi中查看本地窗口,则所有内容都将正确填充,但不会填充返回的实际结果。它仅影响嵌套的条目。有人知道我在做什么错吗? (我从EF6中的数据库创建了模型)

            var student = dbEF.Accounts
                        .Where(x => x.AccountNumber == acctNum)
                        .Select(x => new DTOCrmDetails()
                        {
                            AccountNumber = x.AccountNumber,

                            CommissionId = x.CommissionId,
                            Commission = x.Commission,

                            ManagerID = x.ManagerID,
                            ManagerName = x.Manager.ManagerName,
                            Manager = x.Manager,

                            Employees = x.Manager.Employees,

                            WireInstructionsUSD = x.Manager.WireInstructionsUSDs

                        //Mapping_ManagersExecutingBrokers = x.Manager.Mapping_ManagersExecutingBrokers

                    }).FirstOrDefault();

        return student;

这些是我的设置。

var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; config.Formatters.Remove(config.Formatters.XmlFormatter); config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

1 个答案:

答案 0 :(得分:0)

您需要在实体框架dbcontext中禁用延迟加载。

类似这样的东西:

dbEF.Configuration.LazyLoadingEnabled = false;