Re: throw exception when insert data with entityframeworkcore
Posted by:
George Wu
Date: August 26, 2016 01:07AM
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("Server=localhost;Port=3306;Database=study;Uid=root;Pwd=so@123456;SslMode=None");
}
public virtual DbSet<SuperForm> SuperForm { get; set; }
public virtual DbSet<Employee> Employee { get; set; }
}
And this is how I insert data:
using (var context = new MyContext())
{
var data = new Employee
{
Id = Guid.NewGuid(),
Name = "George",
Age = 30,
Department = "IT"
};
context.Employee.Add(data);
Console.WriteLine(context.SaveChanges());
}
I've also tried to use attribute "Table" to specify table name for my entity, but not work.
Query data is fine with this code:
using (var context = new MyContext())
{
var data = context.Employee.ToList();
foreach (var employee in data)
{
Console.WriteLine(employee.Department);
}
}
Subject
Written By
Posted
Re: throw exception when insert data with entityframeworkcore
August 26, 2016 01:07AM
September 11, 2016 04:38PM
September 11, 2016 05:02PM
September 20, 2016 02:17PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.