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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:29:39+00:00 2026-06-09T15:29:39+00:00

I am very new to Entity Framework and so I don’t know the technical

  • 0

I am very new to Entity Framework and so I don’t know the technical terms use in it. I am sorry for my bad English.

I am working in a project which has entity framework in it and has an .edmx file. The file has entities created in it.

So I created 2 entities and named it TableA and TableB.
pid is entity key of TableA and cid is entity key of TableB .
And created many to one relationship in it.
i.e. TableA row1 can have TableB_cid=1
TableA row2 can also have TableB_cid=2

And then I did “Generate database from model”

CREATE TABLE [TableA] (
    [pid] nvarchar(max)  NOT NULL,
    [name] nvarchar(max)  NOT NULL,
    [TableB_cid] nvarchar(max)  NOT NULL
);
GO


CREATE TABLE [TableB] (
    [cid] nvarchar(max)  NOT NULL,
    [name] nvarchar(max)  NOT NULL
);

pid|name|TableB_cid
--------------------
1 | a | 2
2 | b | 2
3 | c | 1


cid|name
------------
1 | s
2 | f

Now in the C# code i wrote this,

TableA obj = repository.All().Single(w=>w.pid == "1")
context.Entry<TableA>(obj).Reference<TableB>(o => o.TableB).Load();

Now this will load the TableB whose cid=1 (but what i actually wanted was to load TableB whose cid=2).

I think its matching primary key to primary key and not TableB_cid (TableA) to cid (TableB).

So what i am doing wrong please help.

Edit:
In short I am looking for a way where I can add association of a Non Primary column of table A with a Primary column of table B in Entity Framework 4.0.
And I don’t want to use linq queries and joins. I have tried but I cant a find a way or option in edmx file where i can do it.
enter image description here

enter image description here

enter image description here
Thanks,

M

  • 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-09T15:29:40+00:00Added an answer on June 9, 2026 at 3:29 pm

    I’m not sure I understand the question, but in your example, are you simply attempting to access the TableB entity of the TableA with Id 1?

    If so, how about this:

    TableA obj = repository.All().Single(w=>w.pid == "1");
    TableB SecondTable = obj.TableB;
    

    SecondTable.cid should be 2, is and obj.pid should be 1. If not, what values are you getting?

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

Sidebar

Related Questions

I am very new to Entity Framework, so apologies if its a very bad
i am very much new to Entity Framework and i just used this in
I am very new to the ADO Entity Framework, and I'm looking for the
I'm very new to Entity Framework, that's my disclaimer! I have a SQL 2008
I'm very new to the Entity Framework and trying to understand how to best
I very new to .NET and Entity Framework, and I have a problem with
I am very new to Entity Framework and data-based application. Let the Customer data
I am very new to the entity framework, so please bear with me... How
I've just started learning how to use the Entity Framework to write a very
I am very new to ADo.net entity framework and i am getting the following

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.