WCF Service not returning virtual property ServiceProvider

404 Views Asked by At
public class Account
{
    [DataMember]
    public int AccountId { get; set; }
    [DataMember]
    public string Email { get; set; }
    [DataMember]
    public string Password { get; set; }
    [DataMember]
    public string ConfirmPassword { get; set; }

    [ForeignKey("ServiceProvider")]
    [DataMember]
    public int ServiceProviderId { get; set; }
    [DataMember]
    public virtual ServiceProvider ServiceProvider { get; set; }
}

When tried with

this.context.Configuration.LazyLoadingEnabled = false;
this.context.Configuration.ProxyCreationEnabled = false;

it return ServiceProvider as null

1

There are 1 best solutions below

4
On

Use eager loading with Include method:

using System.Data.Entity;
//...
context.Accounts.Include(x => x.ServiceProvider).Where(...)

See this topic for clarification: What are the downsides to turning off ProxyCreationEnabled for CTP5 of EF code first