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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:39:37+00:00 2026-06-18T12:39:37+00:00

Models: public class User { [Key] public int UserId { get; set; } public

  • 0

Models:

 public class User
 {
     [Key]
     public int UserId { get; set; }
     public string UserName { get; set; }
 }

public class Resource
{
    [Key]
    public int ResourceId { get; set; }
    public string ResourceName { get; set; }
    public string  ResourceDescription { get; set; }
}

public class UserResource
{
    [Key, Column(Order=0)]
    public int UserId { get; set; }
    [Key, Column(Order=1)]
    public int ResourceId { get; set; }
    public int ResourceQuantity { get; set; }
}

I want to select “ResourceName” from Resource model and “ResourceQuantity” from UserResource model for a given “UserId”. Also, once selected, do I need a brand new model to carry only those two specified columns?

Also note that UserResource model has a composite key so I am confused as to how to make the join… Is this right?

 var userResources =
          from r in imDB.Resources
          join ur in imDB.UserResources
          on r.ResourceId equals ur.ResourceId
          select new { r.ResourceName, ur.ResourceQuantity };
  • 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-18T12:39:38+00:00Added an answer on June 18, 2026 at 12:39 pm

    Hence you’re using Code first you can create your models are as below by using EF conventions.

    public class User {
        public int Id { get; set; }
        public string UserName { get; set; }
    
        public virtual ICollection<Resource> Resources { get; set; }
       }
    
    public class Resource {
        public int Id { get; set; }
        public string ResourceName { get; set; }
        public int ResourceQuantity { get; set; }
    
        public virtual ICollection<User> Users {get;set;}
    }
    

    Then EF will generate your junction table is as UsersResources.You don’t need to create additional model as you did.EF will look after that.

    When using POCOs with EF, if you mark your navigation properties as
    virtual you can use additional EF supports like Lazy Loading. So in
    general use a virtual keyword in navigation properties considered to
    be a good practice.

    UPDATE

    You may try something like below:

    Method 1 : Method based syntax

    imDB.Resources.Where(r => r.Users.Any(u => u.UserId == userId))
    

    Method 2 : Query based syntax

    from r in imDB.Resources
    from u in r.Users
    where u.UserId == userId
    select r;
    

    I hope this will help to you.

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

Sidebar

Related Questions

i have these two models public class Group { [Key] public int GroupID {
My Model: public class Country { public int CountryId { get; set; } public
So I have the following models public class User { public int Id {
I have the following Models : public class EvaluationCriteriaItem { public int ID {
Here's my model: public abstract class Entity { public long Id { get; set;
My context is: public class RegistrationManagerContext : DbContext { public DbSet<User> Users { get;
Here is my simplified code: // Domain models public class Order { public int
I am using EntityFramework 4.1. I have the following model: public class User {
First, a simple example to describe my problem. Model public class User { public
i created a model object in PHP class User { public $title; public function

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.