entity framework 4 - Using CreateSourceQuery in CTP4 Code First -
I think this is impossible, but I will remove it anyway. Is it possible to use CreateSourceQuery while programming with the EF4 CodeFirst API in CTP4? I want to do this in relation to the properties attached to a collection of properties, impartially:
on sourceQuery = this.CurrentInvoice.PropertyInvoices.CreateSourceQuery (); SourceQuery.Include ("property") toList () .;
But definitely EntityCollection is defined on CreateSourceQuery, it is defined by T & gt;,
while using CodeFirst plain old ICollection
(Obviously). Is there any way to convert?
I have given down to work, but this is not enough which I see. Anybody know that in the above version which is given below (what is the code given below which refers to dubnexation)?
ObjectSet person & gt; OSPeople = base.ObjectContext.CreateObjectSet & lt; Person & gt; (); OSPeople.Include (Pensor => Piner Books) .Oolist ();
Thanks!
EDIT: Here is my version of the solution posted by Zeissenhorry - the way the book is amazing!
Dynamic results; Result = (EntityCollection & lt as invoices.PropertyInvoices; PropertyInvoice & gt;) if (; PropertyInvoice & gt invoice.PropertyInvoices EntityCollection & lt). CreateSourceQuery () Yadda.Yadda.Yadda rest // should be tested on a unit! Result = Invoice. Property invoice; Return Results. Toolist ();
EDIT2:
OK, I realized that you can not transmit extension methods when using dynamic. So I think we are not dynamic in the form of enough , but the above versions are easily compromised with this restriction
EDIT3:
As told that in the blog post of Zeisseniharni, it works only if you (and only if) you have a change-enabled proxy, which is all of your properties virtual Is declared. Perhaps another version of how to use CreateSourceQuery with POCO
public class person {public virtual ID (get; set;} public virtual string FName {get; set;} Public Virtual String LName {get} set;} Public virtual double weight {get; set;} public virtual icon & lt; book & gt; books {received; set;}} public class book {public virtual id id {get; set ;} General A virtual string title {get; set;} public virtual item {get};} public virtual int owner id {get; set;} public virtual icon & lt; genre & gt; styles {get; set;} public Virtual Person Owner {Received; Set;}} Public Class Genre {Public Virtual Ent ID {get; Set;} Public Virtual String Name {get; set;} Public Virtual Style ParentGenre {get; set;} Public Virtual Icons Shn & lt; book & gt; Books {get; set;}} public class BookContext: .. DbContext {public void PrimeBooksCollectionToIncludeGenres (Person p) {if (P.Books EntityCollection & lt; Book & gt;) (Enter EntityCollection & lt as P.Books; Book & gt;) Include CreateSourceQuery (b = & gt; B styles) .toList (); }
It is definitely possible to do this. If you have marked the virtual
keyword, then at the runtime with the store property, then you will have the actual solid type for ICollection
EntityCollection
which supports CreateSourceQuery
and all the stuff that comes with the default code generator. Here is how I would have done this
public class invoice {public virtual icollection propertyInvoices {get; Set}}. Dynamic invoice = this.Invoice; Dynamic Invoice = Invoice Property Invoice CreateSource () Include ("property");
I wrote a blog post in a similar way. Just be aware that there is no good practice to convert to EntityCollection
to rely on the underlying implementation of Icoding
. Below is a blog post that you can find useful
Comments
Post a Comment