I have 2 classes SiteConfig, SiteConfigView. One is tightly coupled with my EF and one class to expose it to View models. Both the classes holds to a collection of type 'Brands'
I struck at writing a linq query to fetch the records from db to view model.
As I am exposing a different class to view model, I have to get the records of type 'SiteConfigView'. So I am writing a linq query but I am bit confused how to get the collection from SiteConfig to SiteConfigView.
There are my classes
public partial class SiteConfig
{
public SiteConfig()
{
this.SiteBrands = new HashSet<SiteBrand>();
}
public int IdSiteConfig { get; set; }
public string Name { get; set; }
public byte[] SiteLogo { get; set; }
public string Brands { get; set; }
public string LinkColour { get; set; }
public virtual ICollection<SiteBrand> SiteBrands { get; set; }
}
public class SiteConfigView
{
public SiteConfigView()
{
}
public int IdSiteConfig { get; set; }
public string Name { get; set; }
public byte[] SiteLogo { get; set; }
public string Brands { get; set; }
public string LinkColour { get; set; }
public IEnumerable<SiteBrandView> SiteBrands { get; set; }
}
And this is the query I am trying
var db = new SampleMVCEntities();
IQueryable<SiteConfig> test = db.SiteConfigs.Select(a => new SiteConfigView{Name = a.Name,LinkColour = a.LinkColour,SiteLogo = a.SiteLogo});
Can comebody guide me how to get the collection from SiteConfig to SiteConfigView.
Thanks