Below is what I am trying to do. I am using Entity Framework 6 and I have a DataLayer Object that I am passing up the layers to a BusinessData Object. Basically get the object from the database and pass its values to a new object that mirrors it in the BusinessData layer.
See below for code.
Entity Framework Generated Object
public partial class SolutionArea
{
public SolutionArea()
{
this.Awards = new HashSet<Award>();
this.Competencies = new HashSet<Competency>();
this.KeyWins = new HashSet<KeyWin>();
this.Offerings = new HashSet<Offering>();
this.Products = new HashSet<Product>();
this.Programs = new HashSet<Program>();
}
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Manager { get; set; }
public string PreSalesCount { get; set; }
public virtual ICollection<Award> Awards { get; set; }
public virtual ICollection<Competency> Competencies { get; set; }
public virtual ICollection<KeyWin> KeyWins { get; set; }
public virtual ICollection<Offering> Offerings { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Program> Programs { get; set; }
}
Data Layer Object
namespace SolutionsEntities.DataAccessObjects
{
public class SolutionAreaDAO
{
public SolutionAreaBDO GetSolutionArea(int Id)
{
SolutionAreaBDO solutionAreaBDO = null;
using(var context = new SolutionsEntities())
{
SolutionArea solutionAreaDAO = (from s in context.SolutionAreas
where s.ID == Id
select s).FirstOrDefault();
if (solutionAreaDAO != null)
{
solutionAreaBDO = new SolutionAreaBDO();
{
solutionAreaBDO.Title = solutionAreaDAO.Title;
solutionAreaBDO.Programs = solutionAreaDAO.Programs;
}
}
}
}
}
Business Data Object
namespace SolutionsBDO
{
public class SolutionAreaBDO
{
public int ID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Manager { get; set; }
public string PreSalesCount { get; set; }
public virtual ICollection<AwardBDO> Awards { get; set; }
public virtual ICollection<CompetencyBDO> Competencies { get; set; }
public virtual ICollection<KeyWinBDO> KeyWins { get; set; }
public virtual ICollection<OfferingBDO> Offerings { get; set; }
public virtual ICollection<ProductBDO> Products { get; set; }
public virtual ICollection<ProgramBDO> Programs { get; set; }
}
}
The problem I have is in the SolutionAreaDAO class above I get an Error saying I cannot convert an ICollection to an ICollection. This is the line of code that causes the issue:
solutionAreaBDO = new SolutionAreaBDO();
{
solutionAreaBDO.Title = solutionAreaDAO.Title;
solutionAreaBDO.Programs = solutionAreaDAO.Programs;
}
Both objects have a property that is a separate entity. SolutionArea object contains a Collection of Program objects. When I try to set the collection from the Data Object to the Business Object I get an explicit cast error.
Error 1 Cannot implicitly convert type 'System.Collections.Generic.ICollection<SolutionsEntities.Program>' to 'System.Collections.Generic.ICollection<SolutionsBDO.ProgramBDO>'. An explicit conversion exists (are you missing a cast?) C:\Projects\SolutionsBackgrounder\SolutionsEntities\DataAccessObjects\SolutionAreaDAO.cs 26 52 SolutionsEntities
I'm sure I'm just not doing tis right but if someone can point me in the right direction it would be much appreciated!
Thanks,
Joe