Extended Property RRS feed

  • Question

  • How do I add a property to an entity object and not have it participate in a Select statement? 

    My entity is derived from a database table but sourced from a stored procedure that returns an additional column...I don't want the DataContext to throw a "column does not exist" exception if loaded from the generated query.

    Basically, I would like to attribute the extended property with "readonly" and "if exists" in the result set.

    • Edited by vze23c3q Sunday, July 5, 2009 1:18 PM
    Sunday, July 5, 2009 1:14 PM

All replies

  • Just add an ordinary property without decoarating it with a [Column] attribute:

      public int Foo { get; set; }

    Because LINQ to SQL's designer generates partial classes, you can do this in the other half of the partial class.


    Write LINQ queries interactively -
    Monday, July 6, 2009 1:33 AM
  • I tried that and without the column attribute, LINQ won't populate the property from the result set.  Some more info:  This is a child entity in a master/child association populated by a shaped stored procedure with the following code (using SetSource):

     public ListDefinition GetListDefinitionEx(int listID)
         IMultipleResults rs = ListContext.GetUserListEx(listID);
         ListDefinition listDefinition = rs.GetResult<ListDefinition>().First();
         return listDefinition;
    I also tried to inherit a new class but couldn't get the master table to create the correct type without overriding it as well.
    Monday, July 6, 2009 9:56 AM