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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:26:34+00:00 2026-05-24T19:26:34+00:00

I have two tables Users and Companies: public class User { // Properties public

  • 0

I have two tables Users and Companies:

public class User
{
    // Properties
    public long Id { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public string Username { get; set; }

    public long AgencyId { get; set; }
    public Company Company { get; set; }

    // Custom Propreties
    [ScaffoldColumn(false)]
    public string FullName
    {
        get
        {
            return FirstName + " " + LastName;
        }
    }
}

public class Company
{
    public long Id { get; set; }

    public string Name { get; set; }

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

The configuration is as so…

public class UserConfiguration : EntityTypeConfiguration<User>
{
    public UserConfiguration()
    {
        this.HasKey(x => x.Id);

        this.Property(x => x.Id);
        this.Property(x => x.FirstName).IsRequired();
        this.Property(x => x.LastName).IsRequired();
        this.Property(x => x.Username).IsRequired();
        this.Property(x => x.CompanyId).IsRequired();

        this.HasRequired(user => user.Company).WithMany().HasForeignKey(user => user.CompanyId);
    }
}

public class CompanyConfiguration : EntityTypeConfiguration<Company>
{
    public CompanyConfiguration()
    {
        this.ToTable("Companies");

        this.HasKey(x => x.Id);

        this.Property(x => x.Id);
        this.Property(x => x.Name).IsRequired();

        this.HasMany(company => company.Users).WithRequired().HasForeignKey(user => user.CompanyId);
    }
}

If I create a view with the Companies to show each company and make one column the Count of Users in the Company, then the View is rendered as expected showing the number of Users in each company. However, when I try to show each user in a View and show there Company.Name in a column, then it says that Company is null. Can someone explain if my one-to-one relationship is screwed up between User and Company?

************ EDIT ****************

    public UserConfiguration()
    {
        this.HasKey(x => x.Id);

        this.Property(x => x.Id);
        this.Property(x => x.FirstName).IsRequired();
        this.Property(x => x.LastName).IsRequired();
        this.Property(x => x.Username).IsRequired();
        this.Property(x => x.CompanyId).IsRequired();

        this.HasRequired(user => user.Company).WithMany().HasForeignKey(user => user.CompanyId);
        this.HasMany(user => user.AdministratorApplications)
            .WithMany(application => application.Administrators)
            .Map(map =>
            {
                map.ToTable("ApplicationAdministrators");
                map.MapLeftKey("ApplicationId");
                map.MapRightKey("UserId");
            });
    }

    public ApplicationConfiguration()
    {
        this.HasKey(x => x.Id);

        this.Property(x => x.Name).IsRequired();
        this.Property(x => x.Accronym).IsRequired();
        this.Property(x => x.Description);

        this.HasMany(application => application.Administrators)
            .WithMany(user => user.AdministratorApplications)
            .Map(map =>
            {
                map.ToTable("ApplicationAdministrators");
                map.MapLeftKey("UserId");
                map.MapRightKey("ApplicationId");
            });
    }

    public ApplicationAdministratorConfiguration()
    {
        this.ToTable("ApplicationAdministrators");

        this.HasKey(x => x.Id);

        this.Property(x => x.Id);
        this.Property(x => x.ApplicationId).IsRequired();
        this.Property(x => x.UserId).IsRequired();

        this.HasRequired(appAdmin => appAdmin.Application).WithMany().HasForeignKey(appAdmin => appAdmin.ApplicationId);
        this.HasRequired(appAdmin => appAdmin.User).WithMany().HasForeignKey(appAdmin => appAdmin.UserId);
    }

Here is the ApplicationAdministrator class

public class ApplicationAdministrator
{
    [Column("Id")]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [HiddenInput]
    public long Id { get; set; }

    [Display(Name = "Application")]
    public long ApplicationId { get; set; }
    public virtual Application Application { get; set; }

    [Display(Name = "Administrator")]
    public long UserId { get; set; }
    public virtual User User { get; set; }
}

And finally the error

Schema specified is not valid. Errors: (144,6) : error 0019: The
EntitySet ‘UserApplication’ with schema ‘dbo’ and table
‘ApplicationAdministrators’ was already defined. Each EntitySet must
refer to a unique schema and table.

Line 15: public IQueryable Users
Line 16: {
Line 17: get { return context.Users.Include(“AdministratorApplications”).Include(“Company”); }
Line 18: }
Line 19:

  • 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-24T19:26:35+00:00Added an answer on May 24, 2026 at 7:26 pm

    You need to make Company property virtual

    public class User
    {
        // Properties
    
        public virtual Company Company { get; set; }
    
    }
    

    If you don’t want to make it virtual you need tell EF to load Company property using the Include method.

    By making the property virtual EF will lazy load the property. But f you are accessing Company property when you access user object then you can use Include method to eager load Company property.

    var users = context.Users.Include(user => user.Company).Where(/*conditions*/);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with these columns: Users: user, class, grade, location. Classes: class,
I have a simple database with two tables. Users and Configurations. A user has
I have two tables: Users and Roles. A user may have more roles, so
I have two tables users registered_members I want to confirm values from user table
I'm trying to set up a project using hibernate.I have two tables : Users
I have two tables, users and groups . A user can belong to many
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
If I have two tables - Logins and Users, as follows: Logins LoginIdNo UserIdNo
We have two tables - Tasks and TasksUsers (users assigned to task). Task has

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.