LINQ to SQL support for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Starting with Windows Phone OS 7.1, apps can use LINQ to SQL to store relational data in a local database. While Windows Phone supports most LINQ to SQL features, there are some limitations. This topic describes those limitations. For more information about using a local database, see Local database for Windows Phone 8.
Note
New features have been added to LINQ to SQL specifically for Windows Phone apps. For example, on a local database you can have multiple indexes and programmatically update the schema. For the API reference for these features, see Microsoft.Phone.Data.Linq and Microsoft.Phone.Data.Linq.Mapping.
This topic contains the following sections.
- LINQ to SQL support
- LINQ to SQL API support
- Related Topics
LINQ to SQL support
Windows Phone supports most LINQ to SQL features; there are some limitations. The following list describes aspects of LINQ to SQL support that should be considered when working with a local database in your app.
ExecuteCommand is not supported: Windows Phone does not support executing “raw” Transact-SQL, Data Definition Language (DDL), or Data Modeling Language (DML) statements.
ADO.NET Objects (such as DataReader) are not supported: All data from a LINQ to SQL query is returned in an object collection of type specified by the data context.
Only Microsoft SQL Server Compact Edition (SQL CE) data types are supported: SQL CE is the underlying database technology for a local database. For a full list of SQL CE data types, see Data Types (SQL Server Compact).
Table.IListSource.GetList Method is not supported: To bind to all contents in a table, query the entire table and bind to the query. Handle inserts and deletes with business logic.
BinaryFormatter is not supported: To convert custom types to a SQL Server Binary or VarBinary data type, your data context property can implement a LINQ to SQL CustomType or be of type byte[] or System.Data.Linq.Binary. To implement a LINQ to SQL CustomType, first create a custom class that implements ToString() and Parse(), and then use that class as a property in your data context. LINQ to SQL can map from CustomType to any SQL Server string types such as Char, NChar, NVarChar, Text, and XML.
Take() requires a constant value in LINQ queries: SQL CE does not support the use of queried values within the Transact-SQL TOP statement. If you want to use a variable value within the Take method, calculate that value in a different query than the one that the Take method is used in.
Skip() and Take() require an ordered list: These methods depend on ordering to return results in a consistent manner.
LINQ to SQL API support
The following tables list the LINQ to SQL APIs that are partially supported and not supported on Windows Phone compared to other platforms. Partial supported means that the API was modified to work with Windows Phone. For complete details about the LINQ to SQL API for Windows Phone, see the class library reference for the following namespaces.
Note
The Microsoft.Phone LINQ to SQL APIs are applicable only to Windows Phone. Because Microsoft.Phone.Data.Linq and Microsoft.Phone.Data.Linq.Mapping are available only on Windows Phone, they are not listed in the following tables.
System.Data.Linq
The following members of System.Data.Linq are partially supported or not supported on Windows Phone.
Name |
Type |
Partially supported |
Not supported |
---|---|---|---|
DataContext |
class |
partial support |
- |
EntitySet<T> |
class |
partial support |
- |
TableSet<T> |
class |
partial support |
- |
IFunctionResult |
interface |
- |
no support |
IMultipleResults |
interface |
- |
no support |
ISingleResult<T> |
interface |
- |
no support |
System.Data.Linq.Mapping
The following members of System.Data.Linq.Mapping are partially supported or not supported on Windows Phone.
Name |
Type |
Partially supported |
Not supported |
---|---|---|---|
MetaDataMember |
class |
partial support |
- |
MetaModel |
class |
partial support |
- |
FunctionAttribute |
class |
- |
no support |
MetaFunction |
class |
- |
no support |
MetaParameter |
class |
- |
no support |
ParameterAttribute |
class |
- |
no support |
ProviderAttribute |
class |
- |
no support |
ResultTypeAttribute |
class |
- |
no support |
XmlMappingSource |
class |
- |
no support |
See Also
Other Resources
How to use the Isolated Storage Explorer tool for Windows Phone 8