Using reflection to address a Linqed property

后端 未结 3 2117
青春惊慌失措
青春惊慌失措 2021-01-03 17:22

I\'m trying to writing a generic method that will load a record of a specific type, with a specific ID. Here\'s one way that works:

    public abstract clas         


        
3条回答
  •  温柔的废话
    2021-01-03 18:05

    Linq to SQL tries to translate your linq-query into SQL, but it does not know how to translate your property to a column name in the DB.

    A good explanation can be found here on SO: simple linq to sql has no supported translation to SQL

    But how to solve it, is another matter. I have with succes used the apporoach from this thread:

    http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/df9dba6e-4615-478d-9d8a-9fd80c941ea2/

    Or you can use dynamic query as mentioned here by scott guthrie:

    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

提交回复
热议问题