Hello, I am a new in EF. I have a Customewr class:
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
And here is my DbContext class:
public class DiveShopContext:DbContext
{
public DbSet<Customer> Customers { get; set; }
}
I want to be able to save Customers to my DB, i do it as follow:
<pre lang="cs">class Program
{
static void Main(string[] args)
{
using (var db = new DiveShopContext())
{
var customer = new Customer();
customer.CustomerId = 3045;
customer.Name = "Alex";
db.Customers.Add(customer);
db.SaveChanges();
}
}
}</pre>
Every thing is saved fine but the CustomerId is changed from 3045 to 1 and saved.