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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:59:02+00:00 2026-06-05T21:59:02+00:00

I have a table called TPM_TASKS which contain all tasks, as well as a

  • 0

I have a table called TPM_TASKS which contain all tasks, as well as a table called TPM_USER which contains all users. I then have a table called TPM_USERTASKS which contains a UserId and TaskId which stores the assignment of one task to one user.

I’m attempting to select all tasks that are assigned to a given TPM_USER entity. So far, I’ve tried:

TPM_USER user = UserManager.GetUser(context, UserId); //Lookup the user in the DB
var tasks = (from t in context.TPM_TASK.Include("TPM_USER")
             where t.TPM_USER.Contains<TPM_USER>(user)
             select t);

However, when I try to iterate into this I get the runtime exception:

Unable to create a constant value of type ‘Entity.TPM_USER’. Only
primitive types (‘such as Int32, String, and Guid’) are supported in
this context.

I believe it doesn’t like me passing in a TPM_USER object into Contains(). This probably makes sense, as it would have to generate a nested SELECT statement rather than an IN clause, which perhaps EF isn’t capable of doing. However, surely there’s a way to do a query like this, right?

NOTE: If you’re clever, you’re probably about to ask me why I don’t just query TPM_USERTASKS and then join in the matching TPM_TASK instead. Well, I’d love to do this. However, I’ve been trying all morning to get EF to generate a TPM_USERTASK model and it simply won’t. The table shows up in the model store, and I can define relationships against it. It doesn’t show up in the list of entities I can add or refresh from the database, and I’ve even tried deleting the entire .EDMX file and creating it again. I’m guessing something that gets used in a many-to-many relationship can’t also be a stand-alone entity?

  • 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-05T21:59:04+00:00Added an answer on June 5, 2026 at 9:59 pm

    Your query would look something like this:

    var tasks = (from t in context.TPM_TASK.Include("TPM_USER")
                where t.TPM_USER.Any(x => x.Id == user.Id)
                select t);
    

    But that’s somehow a little bit off anyway. The TPM_USER object should already have a reference to TPM_TASK.
    So user.TPM_TASKS should give you all the tasks of the given user, otherwise your model is somehow wrong.

    TASKS many-to-many USERS
    means:
    One Task, many users.
    One user, many Tasks.

    Or am I wrong?

    Update:

    If you really want to get the TPM_USERTASKS class in your model you’d have to add a separate Key/Id to it.

    create table TPM_USERTASKS (
        ID      int identity(1,1)   not null
        UserId  int                 not null,
        TaskId  int                 not null,
        constraint [PK_TPM_USERTAKS] primary key (ID)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have table called as Support, which have a field named Name and contains
i have table called type which contains data family,individual i want in some pages
I have table called FinalForgotten which only contains one field called aname. The field
I have table called Buttons. Buttons table i have column button_number . Table contain
I have table called page which represents every single page in my website. page_id
Hi I have table called Sold Products which stores buying information for product &
I have a table called users, with a field full_name. most of the entries
I have a table called USERS that has a foreign key to the table
I have table of users called users and log table called ulog . Every
I have table in my SQL Server database called OrderDetail which stores the order

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.