i'm beginer to Entity Framework
Data Entity ModelConfiguration ModelValidationException when insert data odatabase
what is the wrong in my code?
Thank in advance!
This is my Object Class
[Table ("customerDetails")]
class customerDetails
{
[Key]
internal int cusId { get; set; }
internal string cusName { get; set; }
internal string cusNic { get; set; }
internal string cusAdd { get; set; }
internal DateTime cusDob { get; set; }
}.
This is DbContext
class cusSave : DbContext
{
public cusSave() : base(@"Server= servername"
+ "; Database= dbname"
+ "; UID= user"
+ "; Pwd= pass") { }
public DbSet<customerDetails> saveCus { get; set; }
}
This is the btn Event
private void btnSave_Click(object sender, EventArgs e)
{
var cus =new Logic.customerDetails
{
cusId = Convert.ToInt32(txtCusId.Text),
cusName = txtcusName.Text,
cusAdd = txtcusAdd.Text,
cusNic = txtcusNic.Text,
cusDob = dtpDob.Value
};
var saveCus = new Logic.cusSave();
saveCus.saveCus.Add(cus);
saveCus.SaveChanges();
}
Solution here
Change object class like this
Thanks Every One
Specially
Graeme_Grant
class customerDetails
{
[Key]
public int cusId { get; set; }
public string cusName { get; set; }
public string cusNic { get; set; }
public string cusAdd { get; set; }
public DateTime cusDob { get; set; }
}
What I have tried:
check all object values before save when assign to object but nothings wrong