Simple way to return anonymous types (to make MVC using LINQ possible)

后端 未结 6 1955
囚心锁ツ
囚心锁ツ 2021-01-05 19:03

I\'d like to implement MVC while using LINQ (specifically, LINQ-to-entities). The way I would do this is have the Controller generate (or call something which generates) th

6条回答
  •  有刺的猬
    2021-01-05 19:36

    Since no one even attempted to answer my question, I will answer it myself..

    It turns out, C# 4.0 supports duck-typing - they call it dynamic typing. However, in using dynamic types to return anonymous types, we lose the benefits of strong types:

    • Compile-time type-checking
    • Performance
    • Intellisense

    I've opened a feature request to have strongly-typed anonymous return types here - if you think this would be a useful addition to C# 5, follow the link and let the .Net team know!

提交回复
热议问题