Is it possible for WCF to transport virtual properties of EF?
Is it possible for WCF to transport virtual properties?
I have these classes on my project:
[DataContract]
class Country
{
[Key, DataMember] public int CountryId { get; set; }
[DataMember] public string CountryName { get; set; }
}
[DataContract]
class Employee
{
[Key, DataMember] public int EmployeeId { get; set; }
[DataMember] public string EmployeeName { get; set; }
[DataMember] public int ResidingInCountryId { get; set; }
[ForeignKey("ResidingInCountryId"), DataMember]
开发者_StackOverflow public virtual Country ResidenceCountry { get; set; }
}
I already have Include
on my WCF:
db.Employees.Include("ResidenceCountry").Where(x => x.EmployeeId == 1);
But I got this error:
The underlying connection was closed: The connection was closed unexpectedly.
That error disappeared if I don't use virtual
If it interest anyone, I don't encounter any error on NHibernate when using virtual
and Fetch
combo
[UPDATE: 2011-05-12 3:05 PM]
I solved my problem by using the solution here: http://www.gavindraper.co.uk/category/entity-framework/
The only difference is I use this.Configuration.ProxyCreationEnabled = false;
instead of this.ContextOptions.ProxyCreationEnabled = false;
. I'm using Entity Framework 4.1
Just making the solution given above by the asker himself (@GreenLantern) clearer (and perhaps the problem) to anyone that ends in this post...
Problem: serializing objects with virtual properties
Solution: set your DBContext object's Configuration.ProxyCreationEnabled to false.
var dbContext = new YourEntityModelObject();
dbContext.Configuration.ProxyCreationEnabled = false;
精彩评论