WayneS wrote:In your article, you have:
var results = db.Customer.Where(c => c.State == "Ohio");
Which is changed to this to limit the query to only the necessary columns:
var results = db.Customer
.Select(x => new
{
x.State,
x.Name,
x.Address,
x.Email
});
Now, I'm not an application developer, but I can see that these two queries are not equal - there isn't a predicate on the second one, so it will get all of the rows in the table. For completeness sake, how would this second query be written to implement this where clause? Is it db.Customer.Where().Select()? Or db.Customer.Select().Where()? or something else? If I'm going to be telling the application developers that they need to change, I need to give them a valid example of how the change should be.
First, you would do the "where", then the "select"
var results = db.Customer
.Where(c => c.State == "Ohio")
.Select(x => new
{
x.State,
x.Name,
x.Address,
x.Email
});
It should mentioned here that the returned object type is a dynamic type, and not the entity type 'Customer'.
This needs to be obeyed as dynamic types are accessible ("known") only within the current function (scope).
If the developers don't already know how to do this then you've got bigger problems.