CODE:
namespace projectnamespace;
public class Northwind : DbContext
{
var DataProvider="SQLite";
string path = Path.Combine(
Environment.CurrentDirectory, "Northwind.db");
WriteLine($"Using {path} database file.");
optionsBuilder.UseSqlite($"Filename={path}");
} else
{
string connection = "Data Source=.;" +
"Initial Catalog=Northwind;" +
"Integrated Security=true;" +
"MultipleActiveResultSets=true;";
optionsBuilder.UseSqlServer(connection);
DESCRIPTION:
- Create your DatabaseContext class
- Inherit it from DbContext
- Override OnConfiguring method
- Create connection string according to database provider.
- Add your connection string as a parameter inside optionsBuilder.UseSqlServer(connectionString) this is an example of SqlServer Databae provider.
- Add your tables as property of DbSet<T> type. these represents the tables.
No comments:
Post a Comment