how to convert Listof class to another listof class.C# L

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
return(frompro in_db.PropertyModels


selectnewPropertyEntity()

{
DealType = pro.DealType,

Department = pro.DealType,

Id = pro.Id,

ProjectName = pro.ProjectName,

PropertyPosts = (

frompos inpro.PropertyPosts selectnewPropertyPostEntity() { Id = pos.Id, PostType = pos.PostType, PropertyModel_Id = pos.PropertyModel_Id}).ToList(),

PropertyType = pro.PropertyType

}).ToList();


Hello,
I have Class of reference second class like thispublic partial class PropertyModel
{
public PropertyModel()
{
this.PropertyPosts = new HashSet<PropertyPost>();
}

public int Id { get; set; }
public string PropertyType { get; set; }
public string DealType { get; set; }
public string Department { get; set; }
public string ProjectName { get; set; }

public virtual ICollection<PropertyPost> PropertyPosts { get; set; }
}
this class has second Property post class like this public partial class PropertyPost
{
public int Id { get; set; }
public string PostType { get; set; }
public Nullable<int> PropertyModel_Id { get; set; }

public virtual PropertyModel PropertyModel { get; set; }
}

Ans I am using this class into WCF services this sevice is generated by EntityFramework and I had created another class like same what I have without partial
now my method is above is will give me error like this :
Error 1 Cannot implicitly convert type System.Collections.Generic.ICollection<BuilderTrackerServer.PropertyPost> to System.Collections.Generic.ICollection<BuilderTrackerServer.PropertyPostEntity>. An explicit conversion exists (are you missing a cast?) D:Live ProjectsBuilderTrackerBuilderTrackerBuilderTrackerServerBuilderTrackerServices.cs 26 51 BuilderTrackerServer
how I can resolved this problem.?

View the full article
 
Back
Top