How does EntityRef work?


  • http://blogs.msdn.com/mattwar/archive/2007/06/21/linq-to-sql-objects-all-the-way-down.aspx:


    "EntityRef and EntitySet don’t actually tie back to the database or LINQ to SQL infrastructure at all. They were designed to be completely free of any such entanglements, having no references back to contexts, connections or other abstractions.  Deferred loading is based on assigning each a simple IEnumerable source, such as a LINQ query.




    "EntitySet provides deferred loading and association management for one-to-one and one-to-many relationships between entities. You can build this yourself, but with EntitySet being built on top of IList<T>, you'll probably be recreating the same wheel. There is nothing about EntitySet<T> that ties the class to LINQ to SQL (other than living inside the System.Data.Linq namespace)."


    Having read this two post, It seems that I can make my own EntityRef or EntitySet class that is capable of deferred loading (Yes, I want to reinvent the wheel). But I don't understand how it's possible when LINQ provider doesn't know the type.(EntityRef doesn't implement any interface also.)


    I copied source of EntityRef(and SourceState it references) from reflector and just changed the name to MyRef and also changed entity class's association field to MyRef from EntityRef. But when I excuted query  LINQ provider didn't assign any instance to it. It was null.

    Thursday, July 03, 2008 7:22 AM

All replies

  • l really have to read those posts but i don't think you can create your own object and make linq to sql guess.

    the signature of those objects are:

    public struct EntityRef<TEntity> where TEntity : class
    public sealed class EntitySet<TEntity> : IList, ICollection, IList<TEntity>, ICollection<TEntity>, IEnumerable<TEntity>, IEnumerable, IListSource where TEntity : class

    I don't think what you are trying to do can be done Stick out tongue, but i will check the posts
    Thursday, July 03, 2008 9:10 AM
  • Could anybody give me the answer?

    Monday, July 07, 2008 6:12 PM