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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:16:02+00:00 2026-05-31T08:16:02+00:00

I have a class Tenant, which links to a User via a TenantUser table

  • 0

I have a class Tenant, which links to a User via a TenantUser table in the database.
This relationship is many => many, though I actually only want to expose the mapping one way.

Tenant has a property

virtual ICollection<User> Users { get; set; }

The User class has no property mapping back.

Is it possible using properties or the fluent API to map the Users property of Tenant so that it collects the Users for a particular Tenant via the TenantUser table.

Is that possible, or does the User class need a Tenant collection in order to specify any kind of mapping?

I will also (optionally) have a

DbSet<TenantUser> 

in the context to manage the intermediary table, but for convenience, I want the property accessible on the Tenant class.

Thanks.

  • 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-31T08:16:03+00:00Added an answer on May 31, 2026 at 8:16 am

    You can define a many-to-many mapping in Fluent API, also if only one collection is exposed in the model classes:

    modelBuilder.Entity<Tenant>()
        .HasMany(t => t.Users)
        .WithMany()
        .Map(x =>
        {
            x.MapLeftKey("TenantId");
            x.MapRightKey("UserId");
            x.ToTable("TenantUser");
        });
    

    You can’t define this relationship with data annotations.

    Be aware that you don’t have a TenantUser entity in a many-to-many relationship in Entity Framework. Therefore you can’t create a DbSet<TenantUser> in your context to manage the link table. EF manages this table internally when you add or delete relationships by adding and removing elements to/from the Tenant.Users collection.

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

Sidebar

Related Questions

Let say I have abstract class called: Tenant and Customer. The tenant in this
I have this comparer for my object Tenant public class TenantComparer : IEqualityComparer<Tenant> {
I have class A, which exposes an event. an object of class B subscribed
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have class in server side and I want use method of this class
I have class B that has class A, this is simplified version of class
I have class GUI so I can create object like this: GUI g1 =
I have class User that contains protected constructor and class Account that has access
I have class A which has ISerializable implemented for custom serialization. Now i need
I have Class which extends JDialog . Have an another JDialog declared inside the

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.