Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:16:39+00:00 2026-06-02T06:16:39+00:00

I am trying to define a one-to-many relationship between my two table in Entity

  • 0

I am trying to define a one-to-many relationship between my two table in Entity Framework in .net 3.5.

City Table

CityId
CityName

Employee Table

 EmployeeId
 EmployeeName
 RegistrationDate
 FK_CityID

I am trying to insert Data in Employee all data inserted Perfectly but FK_CityID is instred NULL.

Insert Button click Code
DateTime dt = new DateTime(2008, 12, 12);

    EmployeeService es = new EmployeeService();
    CityService cs = new CityService();
    Payroll.Entities.Employee e1 = new Payroll.Entities.Employee();

    Payroll.Entities.City city1 = cs.SelectCity(Convert.ToInt32(cmbCity.SelectedItem.Value));

    e1.FK_CityID = city1;
    e1 = Payroll.Entities.Employee.CreateEmployee(0, "Archana",dt);
    es.AddEmpoyee(e1);

In e1.City I am Passing whole object that is city1(object of city) and it is passing Perfectly but In database it will save NULL

MyService Class is

public string AddEmpoyee(Payroll.Entities.Employee e1)
        {
            //DAO
            Payroll_DAO payrollDAO = new Payroll_DAO();
            payrollDAO.AddToEmployee(e1);
            payrollDAO.SaveChanges();
            return "SUCCESS";
        }

I am not getting where I am wrong…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:16:42+00:00Added an answer on June 2, 2026 at 6:16 am

    Hi I got the solution..

    Payroll.Entities.City city1 = new Payroll.Entities.City();
    city1 = cs.SelectCity(Convert.ToInt64(cmbCity.SelectedItem.Value));
    
    e1.EmployeeName = "Archana";
    e1.RegistrationDate= dt;
    e1.FK_CityID = city1;
    
    es.AddEmpoyee(e1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to define a simple one-to-many relationship between two poco's , using the
I am trying to define a one to many relationship between Category and Project
I'm trying to do the following, define two classes whose instances mutually reference one
I'm trying to define a many-to-one field in the class that is the Many.
Suppose I have two entities: User and UserGroup . They have a one-to-many relationship
I am trying to setup editing functionality using MVC3 and entity framework 4. I
I'm using Rails 3 and I've got a one to many association I'm trying
For each entity that has a one to many relation with other entity when
I've got a many to many relationship between items - itemnames - languages The
I'm trying to design a code where one guess a number. I defined the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.