Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq query to retrieve collection from one class to another class
    text
    copied!<p>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'</p> <p>I struck at writing a linq query to fetch the records from db to view model.</p> <p>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.</p> <p>There are my classes </p> <pre><code>public partial class SiteConfig { public SiteConfig() { this.SiteBrands = new HashSet&lt;SiteBrand&gt;(); } 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&lt;SiteBrand&gt; 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&lt;SiteBrandView&gt; SiteBrands { get; set; } } </code></pre> <p>And this is the query I am trying</p> <pre><code>var db = new SampleMVCEntities(); IQueryable&lt;SiteConfig&gt; test = db.SiteConfigs.Select(a =&gt; new SiteConfigView{Name = a.Name,LinkColour = a.LinkColour,SiteLogo = a.SiteLogo}); </code></pre> <p>Can comebody guide me how to get the collection from SiteConfig to SiteConfigView.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload