LINQ to SQL supports lazy loading individual properties. In the DBML designer, you can set Delay Loaded
to true
in a column's properties. Columns that are delay loaded will not be included in the initial SELECT
. If you try to access the object's property and it has not been loaded yet, then another SELECT
statement will be executed to bring this value from the DB.
If you are editing the DBML file by hand, set <Column IsDelayLoaded="true">
. If you are writing your LINQ to SQL classes by hand, it is as simple as declaring the property's backing field as a Link<T>
instead of T
. For example:
[Table]
public class Person
{
private Link<string> _name;
[Column(Storage = "_name")]
public string Name
{
get { return _name.Value; }
set { _name.Value = value; }
}
}
See also the "Delay/Lazy Loading" section in this post by Scott Guthrie.
Update: The above answer applies if you want the column to still be available when you need it. It will not be included in SELECT
s unless you specifically ask for it (see LoadOptions
) or try to access it.
If you just don't want to use or access the column at all, and you don't want it available as a class property, then go with Serapth's answer of removing the column from the DBML file. Be sure you understand the implications, such as the loss of concurrency checking on that column.