Ignore read-only class properties when using DataContext.ExecuteQuery

后端 未结 2 1708
忘了有多久
忘了有多久 2021-02-15 02:46

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

相关标签:
2条回答
  • 2021-02-15 03:29
    public bool IsPaidInFull
    {
        get { return NetTotal <= 0m; }
        private set { ;}
    }
    
    0 讨论(0)
  • 2021-02-15 03:35

    Have you considered Linq to Entities? It may not be worth the trouble to convert your project, depending on how far along you are, or how much orm overhead you are comfortable with. However, this exact scenario would not be a problem in Linq to Entities. It does not try to update read only properties in the object when loading it, because they are not explicitly mapped, they are simply extension properties.

    Also, you could go the old-school/java route by using getter functions instead of properties. public bool getIsPaidInFull(){return NetTotal <= 0m;}.

    Or you could play around with implementing the read only properties in an inherited child class, but that may introduce all sorts of type issues.

    0 讨论(0)
提交回复
热议问题