Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 participate in relationship

Author  Topic 

mamor90
Starting Member

5 Posts

Posted - 2013-03-16 : 10:46:03
I am trying to save to the database tables "Employee" and "Employee_languages" I am recieving this following error (upon saving?)
Entities in 'knowitCVdbEntities.EMPLOYEE_LANGUAGES' participate in
the 'FK_EMPLOYEE_LANGUAGES_EMPLOYEES' relationship. 0 related 'EMPLOYEES' were found.

1 'EMPLOYEES' is expected.

This is my method for saving

public void setEmployee(string fileName)
{

var emp = new EMPLOYEE
{
firstname = TextBoxFirstName.Text,
lastname = TextBoxLastName.Text,
about = TextBoxAboutYou.Text,
phone = TextBoxPhone.Text,
position = TextBoxPosition.Text,
email = TextBoxEmail.Text,
username = TextBoxUsername.Text,
date_of_birth = TextBoxDateOfBirth.Text,
image = FileUploadPicture.FileName
};
var emplanguages = new EMPLOYEE_LANGUAGES();
{
emplanguages.language_name = ListBoxLanguages.Text;

}



var db = new knowitCVdbEntities();
db.AddToEMPLOYEES(emp);
db.AddToEMPLOYEE_LANGUAGES(emplanguages);
db.SaveChanges();
}

I was under the assumption that my code was correct, but there must be something wrong. What seems to be the issue here?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-16 : 21:41:56
Is there a foreign key relationship between EMPLOYEE_LANGUAGES and EMPLOYEE, or perhaps is there a link table that has EMPLOYEE ID and LANGUAGE ID? Look at the tables in the database using SSMS - that is the only way I can think of to figure out what is going on (and perhaps the simplest).
Go to Top of Page
   

- Advertisement -