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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:45:19+00:00 2026-05-31T04:45:19+00:00

i have entity classes below,i want to a query like sql,how is that posssible

  • 0

i have entity classes below,i want to a query like sql,how is that posssible with entity framework??

select * from SiteUsers su
inner join SiteUserRoles sur on su.Id=sur.SiteUserId
inner join SiteRoleActions sra on sur.SiteRoleId = sra.SiteRoleId
inner join SiteActions sa on sa.Id = sra.SiteActionId
where su.Id=1 and sa.ParentId=189



  public class SiteRole
    {
        public SiteRole()
        {
            this.SiteActions = new HashSet<SiteAction>();
            this.SiteUser = new HashSet<SiteUser>();
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public virtual ICollection<SiteAction> SiteActions { get; set; }
        public virtual ICollection<SiteUser> SiteUser { get; set; }
    }

 public partial class SiteUser
    {
        public SiteUser()
        {
            this.SiteRoles = new HashSet<SiteRole>();
        }

        public int Id { get; set; }
        public string Email { get; set; }
        public string UserPassword { get; set; }
        public string UserName { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public Nullable<System.DateTime> DateCreated { get; set; }

        public virtual ICollection<SiteRole> SiteRoles { get; set; }
    }

 public partial class SiteAction
    {
        public SiteAction()
        {

            this.Childs = new HashSet<SiteAction>();
            this.SiteRoles = new HashSet<SiteRole>();
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public string ImagePath { get; set; }
        public string ActionName { get; set; }
        public string ControllerName { get; set; }
        public Nullable<int> ParentId { get; set; }
        public Nullable<int> Type { get; set; }


        public virtual ICollection<SiteAction> Childs { get; set; }
        public virtual SiteAction Parent { get; set; }
        public virtual ICollection<SiteRole> SiteRoles { get; set; }
    }

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<SiteUser>().HasMany<SiteRole>(r => r.SiteRoles).WithMany(u => u.SiteUser).Map(m =>
        {
            m.ToTable("SiteUserRoles");
            m.MapLeftKey("SiteUserId");
            m.MapRightKey("SiteRoleId");
        });

        modelBuilder.Entity<SiteRole>().HasMany<SiteAction>(r => r.SiteActions).WithMany(u => u.SiteRoles).Map(m =>
        {
            m.ToTable("SiteRoleActions");
            m.MapLeftKey("SiteRoleId");
            m.MapRightKey("SiteActionId");
        });



        modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    }
  • 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-05-31T04:45:20+00:00Added an answer on May 31, 2026 at 4:45 am

    Since you don’t have SiteUserRoles and SiteRoleActions as entities but only as join tables (if I read you well), you should use the navigation properties in stead of joining. Something like:

    conext.SiteUsers.Where(su => su.id == 1
        && su.SiteRoles.SelectMany(sr => sr.SiteActions)
            .Any(sa => sa.ParentId == 189 )
    

    (Not syntax checked).

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

Sidebar

Related Questions

I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I'm trying to add an object created from Entity Data Model classes. I have
I have several entity classes that I use for parsing fixed width text files
We have C# entity classes which map to some of our SQL Server database
I have hibernate query as below: String mySql = SELECT S.col1, S.col2, T.col3, T.col4,
I have the below classes defined, @Entity @Idclass(Key.class) public void ClassA { ... @Id
Within the realm of Entity Framework, if I have 2 seperate classes leveraging a
I have two entity classes annotated in the following way @Entity class A {
I have two Entity classes: Order and OrderItem . Order contains a navigation property
I have the two entity classes, User and MyCharacter. User has a list of

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.