Entity framework serialize POCO to JSON

前端 未结 4 1156
旧时难觅i
旧时难觅i 2020-12-20 08:40

I\'m using Ef 4.1 and I\'ve got a POCO object I\'d like to serialize to JSON, I\'ve read there is a problem to do so when using lazy loading but I\'m not sure I can because

4条回答
  •  误落风尘
    2020-12-20 09:04

    Eager load it using Include(). Sample linq:

    var serializeMe = (from m in MyContext.Message.Include("User") where m.Id == someValue select m).ToList();
    

    That will tell EF to load the User navigation property right away instead of lazy loading it, and the serializer should have no problem with it then.

提交回复
热议问题