LINQ to SQL support for Windows Phone 8

May 10, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

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.

NoteNote:

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.

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.

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.

NoteNote:

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

Show:
© 2014 Microsoft