Table of contents
Collapse the table of content
Expand the table of content

SqlEntityConnection Type Provider (F#)

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

Provides the types to access a database, using a LINQ to Entities mapping. This type provider is useful when you are using the ADO.NET Entity Model for a database.

Namespace/Module Path: Microsoft.FSharp.Data.TypeProviders

Assembly: FSharp.Data.TypeProviders (in FSharp.Data.TypeProviders.dll)


type SqlEntityConnection<?ConnectionString : string,
                         ?ConnectionStringName : string
                         ?LocalSchemaFile : string, 
                         ?Provider : string,
                         ?EntityContainer : string,
                         ?ConfigFile : string,   
                         ?DataDirectory : string, 
                         ?ResolutionFolder : string,
                         ?ForceUpdate : bool,
                         ?Pluralize : bool,
                         ?SuppressForeignKeyProperties : bool>

Static Type Parameters

Type ParameterDescription
?ConnectionString : stringThe connection string for the database connection.
?ConnectionStringName : stringThe name of the connection string for the database connection in the configuration file.
?LocalSchemaFile : stringThe path to a .csdl file that contains the schema. This parameter is often used with ForceUpdate set to true.
?Provider : stringThe name of the ADO.NET data provider to be used. The default is System.Data.SqlClient.
?EntityContainer : stringThe name to use for the generated type that represents the container for the entities, also known as the data context. The default value is EntityContainer.
?ConfigFile : stringThe name of the configuration file that’s used for connection strings. The default value is app.config or web.config.
?DataDirectory : stringThe name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.
?Resolution Folder : stringA folder to be used to resolve relative file paths at compile time. The default value is the folder that contains the project or script.
?ForceUpdate : boolDetermines whether the type provider updates the generated types to reflect changes in the database schema. When ForceUpdate is false, the provider reacts to changes in the LocalSchemaFile. The default value is true.
?Pluralize : boolIf true, uses plural forms for the generated type names. The default value is false.
?SuppressForeignKeyProperties : boolExclude foreign key properties in entity type definitions. The default value is false.


For a walkthrough that shows how to use this type provider, see Walkthrough: Accessing a SQL Database by Using Type Providers and Entities (F#).

The Entity Data Model Framework is a library for the .NET Framework that allows you to define a database schema largely independent of a specific data source (such as a SQL database). For more information, see ADO.NET Entity Framework and Entity Framework Overview. Database schemas that are represented by the Entity Data Model are encoded in a specific XML format in files with the .edmx extension.

The following table describes types generated by the SqlEntityConnection type provider for a declaration of the form:

type MyDb = SqlEntityConnection<parameters>

In the following table, EntityContainer is the single type generated by edmgen.exe, which has base type System.Data.Objects.ObjectContext. This is the value of the static parameter EntityContainer, if it is given. Otherwise, it is the name chosen by edmgen.exe.

|Type|Description| |----|-----------| |MyDb|The overall container type.

Contains a method GetDataContext that returns a simplified view of the data context. The method returns a new instance of MyDB.ServiceTypes.SimpleDataContextTypes.EntityContainer. The version with the connectionString parameter may be used when the connection string is determined at runtime.| |MyDb.ServiceTypes|Contains the embedded full types and simplified types for the database.| |MyDb.ServiceTypes.*|The embedded types generated by EdmGen.exe.| |MyDb.ServiceTypes.EntityContainer|The data context type, inherited from System.Data.Objects.ObjectContext.| |MyDb.ServiceTypes.SimpleDataContextTypes.EntityContainer|Contains one method for each method of the full context type, including stored procedures and functions. The methods return System.Data.Linq.ISingleResult.

Contains one property for each property of the full context type. The properties return System.Data.Linq.Table.

The property Connection gets the database connection as an instance of System.Data.Common.DbConnection.

The property DataContext gets the full data context, of type System.Data.Objects.ObjectContext. This is the base type of the EntityContainer type generated by the type provider.| The Entity Data Model connection string that you specify at runtime when you call GetDataContext resembles the following:

metadata=res://*/entityNamespaceName.csdl|res://*/entityNamespaceName.ssdl|res://*/entityNamespaceName.msl;provider=provider;provider connection string="connectionString"

For more information about connection strings for the Entity Data Model, see Connection Strings


Windows 8, Windows 7, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 4.0

See Also

Microsoft.FSharp.Data.TypeProviders Namespace (F#)

Walkthrough: Accessing a SQL Database by Using Type Providers and Entities (F#)

EdmxFile Type Provider (F#)

EDM Generator (EdmGen.exe)

Entity Framework Overview

© 2019 Microsoft