tags:

views:

25

answers:

1

for example, I have a table TableA, with fields Field1, Field2 and Field3. My LINQ to SQL code is:

from c in a.TableAs select c

then I bind this query to a GridView named gvSample which only uses Field1 and Field2 of TableA.

then, when the LINQ to SQL query is enumerated, does the data of Field3 will be returned?

A: 

Simply, yes - you are selecting the full entity, so all mapped fields will be returned, regardless of how they are bound to up-stream components such as the GridView.

If you only wanted to return a subset of fields from the database then your query would be more like this:

from c in a.TableAs select new { Field1, Field2 }

This will select Field1 and Field2 only from the database table, into an anonymous type which is still suitable for binding to a GridView. You could also project into a well-known object if you didn't want to use an anonymous type:

from c in a.TableAs select new MyEntity() { Prop1 = c.Field1, Prop2 = c.Field2 }
Sam
thanks very much. can you provide a link to some document like MSDN that detailed describes this?
Brent Jiang