i'm developing an app for a veterinary clinic in winforms.
i have this table named "petOwner" which gives a foreign key to the table "Pets". now when im trying to register a pet i get information of both the owner and the pet from the user,enter code here
the owner is saved successfully (savechanges()!=0) but when it comes to pet it gives me the entity validation err on the following code where triple starred:
if (gpbx_ownerInfo.Enabled==true)
{
objOwner.name = txt_ownerName.Text;
objOwner.family = txt_ownerFamily.Text;
objOwner.mobile = txt_ownerMobile.Text;
objOwner.tel = txt_ownerTel.Text;
objOwner.address = rtxt_ownerAdrs.Text;
objOwner.comment = rtxt_ownerCmnt.Text;
if (txt_ownerName.Text != "" & txt_ownerFamily.Text != "" & txt_ownerMobile.Text != "" & rtxt_ownerAdrs.Text != "")
{
if (objDB.Tbl_ownerInfo.Where(x => x.name == txt_ownerName.Text & x.family == txt_ownerFamily.Text & x.mobile == txt_ownerMobile.Text).ToList().Count == 0)
{
objDB.Tbl_ownerInfo.Add(objOwner);
}
else
{
MessageBox.Show("This keeper already exist\nTry finding them using the 'Keeper already Registered' link.");
}
}
else
{
MessageBox.Show("Fill the starred items please");
txt_ownerName.BackColor = Color.MistyRose;
txt_ownerFamily.BackColor = Color.MistyRose;
txt_ownerMobile.BackColor = Color.MistyRose;
rtxt_ownerAdrs.BackColor = Color.MistyRose;
}
if (objDB.SaveChanges() != 0)
{
gpbx_ownerInfo.Enabled = false;
objPet.ownerID = objDB.Tbl_ownerInfo.Max(s => s.ID);
objPet.name = txt_petName.Text;
objPet.species = txt_petSpecies.Text;
objPet.breed = txt_petBreed.Text;
objPet.birthDate = dt_petBDate.Value.Date;
if (cbox_petGender.Text == "Male")
{
objPet.gender = true;
}
else if (cbox_petGender.Text == "Female")
{
objPet.gender = false;
}
else
objPet.dominatingClr = txt_petClr.Text;
objPet.distinguishingMarks = rtxt_petMarks.Text;
if (txt_petName.Text != "" & txt_petSpecies.Text != "" & cbox_petGender.Text != "" & txt_petClr.Text != "" & cbox_petGender.Items.Contains(cbox_petGender.Text))
{
if (objDB.Tbl_Pets.Where(p => p.name == txt_petName.Text & p.species == txt_petSpecies.Text & p.breed == txt_petBreed.Text & p.dominatingClr == txt_petClr.Text).ToList().Count == 0)
{
objDB.Tbl_Pets.Add(objPet);
***if (objDB.SaveChanges() != 0)***
{
gpbx_ownerInfo.Enabled = true;
textCleaner();
MessageBox.Show("Pet registered successfully");
}
}
else
{
gpbx_ownerInfo.Enabled = false;
MessageBox.Show("This pet already exists");
}
now i know a lot of people don't get this in winforms they usually face it in asp.net and i've searched a lot but every body has given answers on asp here is the exception:enter image description here