Linq To SQL problem - has no supported translation to SQL (problem with C# property)

前端 未结 1 1553
长发绾君心
长发绾君心 2021-02-07 12:12

I\'m extending some Linq to SQL classes. I\'ve got 2 similar statements, the 1st one works, the 2nd does not (\"has no supported translation to SQL\" error).

1条回答
  •  星月不相逢
    2021-02-07 12:45

    Would be great if there was some magic attribute that I could just add to the property to "auto-expression" the property and make LinqToSql happy, instead of wrapping it in Expression<...>

    There is, very nearly. You'll still have to do some work, but Damien Guard and friends have done the hard part for you: Client-side properties and any remote LINQ provider

    The cool thing is that it works with any LINQ provider which supports the Expressions you use.

    Update: The problem with your second version (with the interface) is that the Queryable provider would need to be able to figure out what the implementor of the interface is, because it needs to transliterate that into a table name. But the whole point of an interface is that the interface user should be agnostic as to the implementing type, so the provider would be working at cross purposes with the interface. So I don't think the second form will work.

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