Have been struggling to fix this for a day now. New to EF as well !!
I require to get my product list together with its child collections.
My Model.tt is in a DataModel.dll and I have reference this in both WCF service and my client. When the entity has child collection, I am getting this error. Guess it is due to the public virtual ICollection of the entity. How can I fix this ?
Trying to put [KnownType(typeof(entity.Name))] in my Model.tt will help ? If so how to get the entity.Name to be passed generically in my Model.tt ?
TRIED :
- Put [Serializable] attribute in my Model.tt
- LazyLoadingEnabled="false"
ERROR CAPTURED IN TRACE LOG:
Type 'System.Data.Entity.DynamicProxies.Entity_Product_F540EDA252AD69FEA102E0C9AB0167D5397996ADA4679FA9C4089B58B9766924' with data contract name 'Entity_Product_F540EDA252AD69FEA102E0C9AB0167D5397996ADA4679FA9C4089B58B9766924:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.
There was an error while trying to serialize parameter http://tempuri.org/:GetAllProductResult. The InnerException message was 'Type 'System.Data.Entity.DynamicProxies.Entity_Product_F540EDA252AD69FEA102E0C9AB0167D5397996ADA4679FA9C4089B58B9766924' with data contract name 'Entity_Product_F540EDA252AD69FEA102E0C9AB0167D5397996ADA4679FA9C4089B58B9766924:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.
AUTO GENERATED ENTITY :
[Serializable]
public partial class Entity_Product
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Entity_Product()
{
this.tbl_ManufacturerDetail = new HashSet<Entity_ManufacturerDetail>();
this.tbl_ProductDetails = new HashSet<Entity_ProductDetails>();
}
public int ProductId { get; set; }
public string Administration { get; set; }
public string Manufacturer { get; set; }
public Nullable<decimal> Price { get; set; }
public Nullable<bool> IsEnabled { get; set; }
public Nullable<System.DateTime> CreatedOn { get; set; }
public string CreatedBy { get; set; }
public Nullable<System.DateTime> UpdatedOn { get; set; }
public string UpdatedBy { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Entity_ManufacturerDetail> tbl_ManufacturerDetail { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Entity_ProductDetails> tbl_ProductDetails { get; set; }
}
[KnownType(typeof(Entity_ManufacturerDetail))]
and[KnownType(typeof(Entity_ProductDetails))]
? – jegtugado