开发者

How do I generate optimized SQL with my (added) partial methods on LINQ entities

开发者 https://www.devze.com 2022-12-21 19:32 出处:网络
Let\'s say I have a Person table with a FirstName and LastName column. I extended the Person LINQ entity class with a get property \"FullName\", that concatenates the first and last names.

Let's say I have a Person table with a FirstName and LastName column. I extended the Person LINQ entity class with a get property "FullName", that concatenates the first and last names.

A LINQ query like: from person... select fullName where id = x

generates SQL selecting all Patient columns, since FullName is evaluated after firing the query. I would like to limit开发者_运维问答 the select clause to only the 2 columns required.

This is a simple example, but the limitation it shows is that I cannot isolate my business/formatting rules but have to embed them in the LINQ query, so they're not reusable (since it is in the select part) or I need select both columns separately, and then concatenate them higher up in the data or business layer with static helper methods.

Any ideas for a clean design using the entity partial classes or extensions?

Thanks


Personally, I'd create a computed column at the table level so it's part of the entity you store in a row

0

精彩评论

暂无评论...
验证码 换一张
取 消