I would like to propose that the Entity Frameworks Connection string retrieved from the <connectionStrings> section of the .config file should not be REQUIRED to have the Metadata specified in it.
I propose this for two reasons, first for consistency and simplicity across data access platforms, a Connection String should be composed the same basic way for what ever SQL Access. Second 90% of the time, the metadata specification can be inferred from the naming convention of the generated model or .tt files.
For those 10% of the time where, for whatever reason the Metadata is NOT the default, there should be a separate Entity Framework Configuration section in the .config file where the metadata information is specified, separating it from the standard information in the connection strhing.
So for example
This would allow, for example, the membership provider AND the entity frameworks to use the same connection string, instead of having to provide the same base connection string twice to two different providers, get rid of a lot of typing errors
I have in fact already done this in my .tt file, but I currently use the appSettings to store the metadata, and I don't have the optional connectionStringName lookup.
I propose this for two reasons, first for consistency and simplicity across data access platforms, a Connection String should be composed the same basic way for what ever SQL Access. Second 90% of the time, the metadata specification can be inferred from the naming convention of the generated model or .tt files.
For those 10% of the time where, for whatever reason the Metadata is NOT the default, there should be a separate Entity Framework Configuration section in the .config file where the metadata information is specified, separating it from the standard information in the connection strhing.
So for example
<connectionStrings>
<add name="RinconEntities" connectionString="metadata=res://*/Dal.RinconDb.csdl|res://*/Dal.RinconDb.ssdl|res://*/Dal.RinconDb.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=RinconCapitan;integrated security=True;"" providerName="System.Data.EntityClient" /-->
</connectionStrings>
Would instead become<connectionStrings>
<add name="RinconEntities" connectionString="data source=(local);initial catalog=RinconCapitan;integrated security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFrameworks>
<connectionMetadata name="RinconEntities" metadata="res://*/Dal.RinconDb.csdl|res://*/Dal.RinconDb.ssdl|res://*/Dal.RinconDb.msl;" [connectionStringName="RinconEntities"]
</entityFrameworks>
So when the Entity Frameworks fires up the construction it looks up the Connection String name provided first in the entityFrameworks connectionMetadata section (it already knows since it is the entity frameworks that the top layer provider is System.Data.EntityClient) if it finds that section with that name it loads up the meta data. Then we check to see if the optional connectionStringName has been specified, if so, look for the connection string with that name, if not look for a connection string with the SAME name.This would allow, for example, the membership provider AND the entity frameworks to use the same connection string, instead of having to provide the same base connection string twice to two different providers, get rid of a lot of typing errors
I have in fact already done this in my .tt file, but I currently use the appSettings to store the metadata, and I don't have the optional connectionStringName lookup.