Why Entity Framework one to one relationship in WCF client-side is null?

i use Entity Framework one to one relationship in WCF server-side,Main code is:

[DataContract]
public class AppType
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [DataMember]
    public int TypeID { get; set; }

    [DataMember]
    public string TypeName { get; set; }
}

[DataContract]
public class App
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [DataMember]
    public long AID { get; set; }

    [DataMember]
    [ForeignKey("AppType")]
    public int TypeID { get; set; }

    [DataMember]
    public DateTime DateAdded { get; set; }

    [DataMember]
    public virtual AppType AppType { get; set; }
    //...
}

Because the Serialize Problem,i must close lazyloading and proxyclass in EF:

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

Now,the WCF Client-side can work,but i can't get "AppType" by "App":

the GetAppByTypeidContentid method is:

public App GetAppByTypeidContentid(string contentid, int typeid)
{
    using (var db = new TagDbContext())
    {
        try
        {
            var app = db.Apps.SingleOrDefault(a => a.ContentID.Trim() == contentid.Trim() && a.TypeID == typeid);
            if (app != null)
            {
                return app;
            }
            else
            {
                throw new Exception("App not exist!");
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
}

Is must use DTO or not? who can help me?thanks

Answers


You turned off lazy loading so you must tell EF to load AppType:

var app = db.Apps.Include("AppType")
            .SingleOrDefault(a => a.ContentID.Trim() == contentid.Trim() && a.TypeID == typeid); 

Need Your Help

Type arguments supplied to .NET generic constructor, yet still causing an error as if not

c# asp.net-mvc razor

I have this snippet of seemingly un-problematic code in my ASP.NET MVC 4 Razor application:

Is Selenium TestRunner actively maintained?

selenium

I am new to the Selenium world. I am curious to know whether Selenium Test Runner is actively maintained or not? Also can you point me to the download package of Selenium Test Runner. I am not able...