简体   繁体   中英

WCF Service not returning virtual property ServiceProvider

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM