none
Entity framework RRS feed

All replies

  • Please spell out exactly what you are after.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, May 29, 2017 12:28 AM
  • Hi SU_Dev,

    Thank you for posting here.

    According to your question is more related to EF, I will move it to ADO.NET Entity Framework and LINQ to Entities forum for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples an tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 30, 2017 2:55 AM
  • Hi SU_Dev,

    Do you mean serialize the result of on to many retrieving records to JSON, if so, we could use Newtonsoft.Json to achieve it. the following sample for your reference.

    using (var db = new Model1())
    {             
        var query = db.Offices;
        var serializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects };
          string json = JsonConvert.SerializeObject(query, serializerSettings);
                    
    }

    #Models

    public class Agent
        {
            public int AgentId { get; set; }
            public string FirstName { get; set; }
            public string Surname { get; set; }
            public int OfficeId { get; set; }
            public virtual Office Office { get; set; }
        }
    
    
        public class Office
        {
            public int OfficeId { get; set; }
            public string Agency { get; set; }
            public string Branch { get; set; }
            public virtual ICollection<Agent> Agents { get; set; }
    
            
        }

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 30, 2017 5:48 AM
    Moderator