What I have:
LINQ to SQL auto generated class, which corresponds to the shape of its SQL table.
TABLEA ======== column1 column2
What I want to do:
Extend TABLEA class to include a new property, whose related column will be present only when a particular stored procedure is called. The stored procedure return type will be of TABLEA.
TABLEA ======== column1 column2 newcolumn3 (always part of the class structure, not always populated)
What I’ve done so far:
Created a partial class with a property and a columnattribute, which works when the stored procedure is called. When a direct table call is made, I get an invalid column exception.
My question is:
How do I extend my LINQ to SQL data class to populate a property from a column which may not be present?
I don’t think that is possible. The point of LINQ to SQL is to provide a direct mapping between a return set schema and an object in .NET. Two different return set schemas, two different objects. You can’t truly think of the stored procedure as returning the same object if the signature of the return is different. It’s more like ‘ObjectWithAdditionalInfo’.
When you start to do these more complex, ambiguous mappings you need a real ORM tool like Microsoft Entities or Hibernate.