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 7976373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:53:41+00:00 2026-06-04T08:53:41+00:00

I have to following problem. I’ve large collection of XML files. In each XML

  • 0

I have to following problem.
I’ve large collection of XML files. In each XML file there are different employees. I have to add the unique employees to the database. In the database each employee has first name, last name and birth date. I want to check whether employee with the same properties already exists in the database and if it doesn’t to insert it.

I’m using the following code:

Entities entities;
entities.AddToEmployee(emp);
entities.SaveChanges();

My employee is connected with another data structure – sales. So I need to add just the employee’s primary key to the sales table but not the whole employee in the database (in case that it already exists).

Thanks in advance!

  • 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-04T08:53:42+00:00Added an answer on June 4, 2026 at 8:53 am

    The ‘Find or Add Pattern’ can be useful in these types of circumstance:

    var db = new YourContext();
    var emp = db.Employees.Find(empID) ?? db.Employees.Add( new Employee { FirstName ="xx" , LastName="xxx"});
    db.SaveChanges();
    

    This way the emp object has been loaded if it exists in the database or created and saved to the database. You might need to replace the Find() with a Where() if you are searching on multiple properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have following problem, the infowindow, gives the same result on different markers. When I
i have following problem: i have these files developer_identity.cer Team_Provisioning_Profile_.mobileprovision In order to package
I have the following problem: I select data from a DB, and for each
I have following problem. I want to create a file system based session storage
I have following problem: in my layout xml I have relative layout in which
I have following problem: My webservice application returns xml data in following order: <my_claims>
I have following problem. I use this tutorial to creating a multiple file uploader:
I have following problem: I have a TabActivity which works well. Inside, there is
I have following problem where I have to group different transactions into timeslots. Suppose
I have following problem: I've got an UITableView with 7 custom cells. Each of

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.