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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:12:44+00:00 2026-06-17T17:12:44+00:00

I am using Entity framework 4, SQLite database with database first approach. I have

  • 0

I am using Entity framework 4, SQLite database with database first approach. I have attached my table structure as a snapshot.

I am able to write/ read data in the Bnb_Company and Bnb_Player tables, but when I try to enter a row into the Bnb_Game table, I get the following error.

enter image description here

Entities in ‘MockStockDbEntities.Bnb_Game’ participate in the ‘Bnb_CompanyBnb_Game’ relationship. 0 related ‘Bnb_Company’ were found. 1 ‘Bnb_Company’ is expected.!

//Reset company values
if (context.Bnb_Company.Count() > 0)
{
    var companydetails = context.Bnb_Company.ToList();
    foreach (var company in companydetails)
    {
        company.ESC = 0;
        company.MarketValue = company.FaceValue;
    }
    context.SaveChanges();
}

if (context.Bnb_Player.Count() > 0)
{
    var playerDetails = context.Bnb_Player.ToList();
    //Reset Player values
    foreach (var player in playerDetails)
    {
        player.NetAmount = 0;
        player.Amount = 1000;
        if (context.Bnb_Company.Count() > 0)
        {
            var companyDetails = context.Bnb_Company.ToList();
            foreach (var company in companydetails)
            {
                if (context.Bnb_Game.Count() > 0 && (context.Bnb_Game.Where(b => b.PlayerId == player.Id && b.CompanyId == company.Id).Count() > 0))
                {
                    var specificCompanyShare = context.Bnb_Game.Where(b => b.PlayerId == player.Id && b.CompanyId == company.Id).FirstOrDefault();
                    specificCompanyShare.Shares = company.DefaultShares;
                }
                else
                {
                    Bnb_Game playerCompanyShare = new Bnb_Game();
                    playerCompanyShare.CompanyId = company.Id;
                    playerCompanyShare.PlayerId = player.Id;
                    playerCompanyShare.Shares = company.DefaultShares;
                    context.Bnb_Game.AddObject(playerCompanyShare);
                }
            }
        }

    }
    context.SaveChanges();
}
  • 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-17T17:12:46+00:00Added an answer on June 17, 2026 at 5:12 pm

    Try using the Entity reference instead of the the Id value.

     Bnb_Game playerCompanyShare = new Bnb_Game();
     playerCompanyShare.Bnb_Company = company;
     playerCompanyShare.Bnb_Player = player;
     playerCompanyShare.Shares = company.DefaultShares;
     context.Bnb_Game.AddObject(playerCompanyShare);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framework Code First Approach. I have following code to insert
I'm tring to insert some records into my Sqlite database using the Entity Framework.
I am using Entity Framework and I have two tables, a contact relationship table
I've built an Entity Framework Model from a simple SQLite database using the 'Entity
I'm using the Entity Framework (.NET 4.0) with SQLite as the underlying database and
This is my first WinForm application using the Entity Framework and I have to
I am following the article Using SQLite Embedded Database with Entity Framework and Linq-to-SQL
Hi i am using entity framework and LinQ. I have a table objects called
I was trying to use SQLite database using ADO.NET Entity Framework 5 and I
I am using Entity Framework Code First and have some Classes with a System.Net.Mail.MailAddress

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.