Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore read-only class properties when using DataContext.ExecuteQuery<T>

How do I tell a LINQ data context to ignore either specific properties, or all readonly properties, when binding a result set to an object?

I am working with some T-SQL statements that are difficult to express using LINQ, so I'm using the ExecuteQuery method of the data context to pass the straight T-SQL to the database.

If my class T has any readonly properties, I get exceptions at runtime when the data context tries to set those properties and fails because there's no setter property. How do I tell the context to ignore those properties?

This is what I'm doing now. It works, but it sucks:

public bool IsPaidInFull {
    get { return NetTotal <= 0m; }
    set { /* needed so linq doesn't choke. Should never be set by hand */ }
}
like image 209
Seth Petry-Johnson Avatar asked Apr 01 '09 23:04

Seth Petry-Johnson


1 Answers

public bool IsPaidInFull
{
    get { return NetTotal <= 0m; }
    private set { ;}
}
like image 152
AndyClaw Avatar answered Sep 25 '22 08:09

AndyClaw