Reputation: 1934
I am new to ASP.NET and I am creating a Web API using sort of code first. I have model class call gender and defined as follow
public class Gender
{
public int Id { get; set; }
public string Description { get; set; }
}
I decided to create a new folder call DBContext
and inside will defined all my DBContext
, so for the gender class I have created GenderDb
and look like follow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace BackAPI.Models
{
public class GenderDB : DbContext
{
// not define yet
}
}
However I am having an issue however with DbContext
not being defined, apparently I am supposed to use Entity Framework, however I want to create my database not through Visual Studio, but using SQL Server 2014 Express.
I did add my data connection and can see that I created a table in SQL Server, however how do I fix DbContext
, if I use EF wouldn't that just create it locally and that not what I want
Upvotes: 0
Views: 26799
Reputation: 11954
Entity Framework, along with Migrations, will help you here.
I suggest you check out this tutorial: Code First to a New Database
Upvotes: 2