How do I generate optimized SQL with my (added) partial methods on LINQ entities
Posted
by Ra
on Stack Overflow
See other posts from Stack Overflow
or by Ra
Published on 2010-02-25T22:49:29Z
Indexed on
2010/03/29
18:03 UTC
Read the original article
Hit count: 192
linq-to-sql
|partial-classes
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
© Stack Overflow or respective owner