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

  • Home
  • SEARCH
  • 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 9272025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:45:59+00:00 2026-06-18T15:45:59+00:00

Hi i try to get some Date from my Database but it wont work

  • 0

Hi i try to get some Date from my Database but it wont work and i really have no Idea why.

I get following Error:

Error: Entities in 'DataBase' participate in the 'FK_MSCourse_Language' relationship. 0 related 'Language' were found. 1 'Language' is expected. 

My Code:

var language = db.Language.Where(x => x.Designation == publicLanguage);

if (language != null)
{
  newCourse.Language = language.SingleOrDefault();
}
else
{
  newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "English");
}

If i do it this way it works, but i want to have it dynamically to Languages from the DataBase.

switch (publicLanguage)
{
  case "French":
    newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "French");
    break;
  default:
    newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "English");
    break;
}

Anyone knows what i am doing wrong?

Thanks,
Markus

  • 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-18T15:46:00+00:00Added an answer on June 18, 2026 at 3:46 pm

    LINQ’s Where operation returns an IEnumerable, which can never be null, making your if block useless. It will always execute newCourse.Language = language.SingleOrDefault(); no matter what.

    I’m also thinking that trying to use == on what is most likely a string variable could be causing you some problems also. I would recommend using the .Equals() method instead, which will actually investigate if the strings are equal. Also, since you’re just trying to grab the first one, why not just do this:

    var language = db.Language.FirstOrDefault(x => x.Designation.Equals(publicLanguage));
    

    This will grab the first one that matches that language, or return null. In such a case, then you can just have an if statement which will then assign English as the language if the language variable is, in fact, null.

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

Sidebar

Related Questions

I try to get some insights from the pages I am administrator on Facebook.
I try to update existing data rows in database but i get that exception:
I have a strange, but definitely serious problem regarding fetching data from some Facebook
I try to get some website attribute (colour of the cell) and compare in
For some reason if I try to get the actual size of mystruct I
I am working on some scraping app, i wanted to try to get it
I try to replace few characters in some string 14/04/2010 17:12:11 and get, for
When I try to install my software in some computers, I used to get
i try to get my FragmentPagerAdapter working, but the examples are a bit to
I try to get the main window handle using following code in Lazarus (Free

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.