Created
November 20, 2013 14:12
-
-
Save diffused/7563830 to your computer and use it in GitHub Desktop.
Example Entity Framework 6 context using connection string in app.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <configuration> | |
| <connectionStrings> | |
| <add name="Store" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Store;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /> | |
| </connectionStrings> | |
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Product | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class StoreContext : DbContext | |
| { | |
| // base name=[ConnectionStringName] | |
| public StoreContext() : base("name=Store") { } | |
| public DbSet<Product> Products { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment