Note that there are some explanatory texts on larger screens.

plurals
  1. POChange EF entity with descendant proxy class
    primarykey
    data
    text
    <p>I have .Net 4.0 application which use EntityFramework 5.0 to access data from MS SQL database.</p> <p>I use database first approach. All tableas are mapped to POCO entities, which has additional properties which contains entities which is recieved from web service.</p> <p>Database:</p> <pre><code>WH_Product (Id, NomenklatureId, SeriesId, Quantity) </code></pre> <p>Service have such data:</p> <pre><code>Nomenklature (Id, Name, Producer...) Series (Id, Number, Date...) </code></pre> <p>POCO entity:</p> <pre><code>Product (Id, NomenklatureId, Nomenklature, SeriesId, Series, Quantity) </code></pre> <p>I have a problem with Repository realisation. I need to implement lazy loading for Nomenklature and Series properties. </p> <p>I make ProductProxy class which implements such loading like this:</p> <pre><code>public class ProductProxy:Product { private Nomenklature _nomenklature; public override Nomenklature Nomenklature { get { if (_nomenklature==null) { _nomenklature = &lt;code for load Nomenklature from webService by base.NomenklatureId&gt; } return _nomenklature; } } private Series _series; public override Series Series { get { if (_series==null) { _series = &lt;code for load Series from webService by base.NomenklatureId&gt; } return _series; } } } </code></pre> <p>Then change Person class to PersonProxy class in DbContext.</p> <pre><code>public class ProductContext:DbContext { ... public DbSet&lt;PersonProxy&gt; Person {get; set;} ... } </code></pre> <p>The load method:</p> <pre><code>public List&lt;Person&gt; GetPersons() { using (var ctx = new ProductContext()) { var persons = ctx.Person.AsEnumerable().Cast&lt;Person&gt;().ToList(); return persons; } } </code></pre> <p>Question: Is this a better way to realize GetPersons method without AsEnumerable().Cast()? Is this another way of changing the entity type with the descendant proxy type?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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