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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:13:03+00:00 2026-06-06T14:13:03+00:00

I have the following classes generated by the Reverse engineering tool (Entity Framework Power

  • 0

I have the following classes generated by the Reverse engineering tool (Entity Framework Power Tools):

The db schema

public class User
{
    public User()
    {
        this.Areas = new List<Area>();
        this.Areas1 = new List<Area>();
        this.Areas2 = new List<Area>();
        this.Areas3 = new List<Area>();
        this.Companies = new List<Company>();
    }

    public int UserID { get; set; }
    public string Name { get; set; }
    public string Login { get; set; }
    public string Password { get; set; }
    public bool ActiveDirectory { get; set; }
    public string Language { get; set; }
    public string Email { get; set; }
    public System.DateTime ValidFrom { get; set; }
    public System.DateTime ValidTo { get; set; }
    public bool AllAreas { get; set; }
    public virtual ICollection<Area> Areas { get; set; }
    public virtual ICollection<Area> Areas1 { get; set; }
    public virtual ICollection<Area> Areas2 { get; set; }
    public virtual ICollection<Area> Areas3 { get; set; }
    public virtual ICollection<Company> Companies { get; set; }
}

public class Area
{
    public Area()
    {
        this.Users = new List<User>();
    }

    public int AreaID { get; set; }
    public string AreaNL { get; set; }
    public string AreaFR { get; set; }
    public string ExternalID { get; set; }
    public int CompanyID { get; set; }
    public int AreaManagerID { get; set; }
    public int DistrictManagerID { get; set; }
    public int VAID { get; set; }
    public virtual User User { get; set; }
    public virtual Company Company { get; set; }
    public virtual User User1 { get; set; }
    public virtual User User2 { get; set; }
    public virtual ICollection<User> Users { get; set; }
}

And the constructors of the mapping files:

    public UserMap()
    {
        // Primary Key
        this.HasKey(t => t.UserID);

        // Properties
        this.Property(t => t.Name)
            .IsRequired()
            .HasMaxLength(100);

        this.Property(t => t.Login)
            .IsRequired()
            .HasMaxLength(50);

        this.Property(t => t.Password)
            .IsRequired()
            .HasMaxLength(50);

        this.Property(t => t.Language)
            .IsRequired()
            .HasMaxLength(2);

        this.Property(t => t.Email)
            .IsRequired()
            .HasMaxLength(150);

        // Table & Column Mappings
        this.ToTable("AreaManager");
        this.Property(t => t.UserID).HasColumnName("UserID");
        this.Property(t => t.Name).HasColumnName("Name");
        this.Property(t => t.Login).HasColumnName("Login");
        this.Property(t => t.Password).HasColumnName("Password");
        this.Property(t => t.ActiveDirectory).HasColumnName("ActiveDirectory");
        this.Property(t => t.Language).HasColumnName("Language");
        this.Property(t => t.Email).HasColumnName("Email");
        this.Property(t => t.ValidFrom).HasColumnName("ValidFrom");
        this.Property(t => t.ValidTo).HasColumnName("ValidTo");
        this.Property(t => t.AllAreas).HasColumnName("AllAreas");
    }

    public AreaMap()
    {
        // Primary Key
        this.HasKey(t => t.AreaID);

        // Properties
        this.Property(t => t.AreaNL)
            .IsRequired()
            .HasMaxLength(50);

        this.Property(t => t.AreaFR)
            .IsRequired()
            .HasMaxLength(50);

        this.Property(t => t.ExternalID)
            .HasMaxLength(50);

        // Table & Column Mappings
        this.ToTable("Area");
        this.Property(t => t.AreaID).HasColumnName("AreaID");
        this.Property(t => t.AreaNL).HasColumnName("AreaNL");
        this.Property(t => t.AreaFR).HasColumnName("AreaFR");
        this.Property(t => t.ExternalID).HasColumnName("ExternalID");
        this.Property(t => t.CompanyID).HasColumnName("CompanyID");
        this.Property(t => t.AreaManagerID).HasColumnName("AreaManagerID");
        this.Property(t => t.DistrictManagerID).HasColumnName("DistrictManagerID");
        this.Property(t => t.VAID).HasColumnName("VAID");

        // Relationships
        this.HasMany(t => t.Users)
            .WithMany(t => t.Areas3)
            .Map(m =>
                {
                    m.ToTable("UserArea");
                    m.MapLeftKey("AreaID");
                    m.MapRightKey("UserID");
                });

        this.HasRequired(t => t.User)
            .WithMany(t => t.Areas)
            .HasForeignKey(d => d.AreaManagerID);
        this.HasRequired(t => t.Company)
            .WithMany(t => t.Areas)
            .HasForeignKey(d => d.CompanyID);
        this.HasRequired(t => t.User1)
            .WithMany(t => t.Areas1)
            .HasForeignKey(d => d.DistrictManagerID);
        this.HasRequired(t => t.User2)
            .WithMany(t => t.Areas2)
            .HasForeignKey(d => d.VAID);

    }

Now if I try to do the following:

        using (var ctx = new FCTestContext())
        {
            // Step 1: add user
            var user = new User
            {
                ActiveDirectory = false,
                Login = "Joske",
                Email = "tst@abc.com",
                Password = "sdfsdff",
                Name = "JoskeVermeulen",
                Language = "NL"
            };

            // Step 2: add an Area

            Company company = new Company { Active = true, CompanyName = "CompanyTest" };

            Area area = new Area
            {
                AreaFR = "Anvers",
                AreaNL = "Antwerpen",
                Company = company,
                User = user
            };
            ctx.Areas.Add(area);


            try
            {
                ctx.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (DbEntityValidationResult validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError validationError in validationErrors.ValidationErrors)
                    {
                        //Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName,
                                          validationError.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                for (Exception eCurrent = ex; eCurrent != null; eCurrent = eCurrent.InnerException)
                {
                    Console.WriteLine(eCurrent.Message);
                }
            }

            Console.ReadLine();

It gives me the error:

Invalid object name dbo.AreaManager. I have clearly not that table and also not the intent on adding it. I should only provide the 3 foreign keys for each manager one and a user should also be able to see all areas.

  • 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-06T14:13:06+00:00Added an answer on June 6, 2026 at 2:13 pm

    And just after jotting everything down and going over the code again after posting one sees where the culprit is :-(.

    It’s in the line

    this.ToTable("AreaManager");
    

    For some reason the tools have generated it like that to be mapped as such in the database. Changing it to

    this.ToTable("User");
    

    Made it work.

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

Sidebar

Related Questions

Assume I have the following two classes: public class User : Entity { public
Suppose, I have following classes: public class DisposableObj : IDisposable { public ChildObj CreateObj();
I have the following classes: public class Base { public int someMethod(){...} } public
I have the following classes in an Entity Framework 4.3 Code-First Model for MVC3:
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
Let's say I have the following two classes: package example.model; public class Model {
I have following classes: class Department { private string departmentId; private string departmentName; private
I have the following classes class ParentDocument(Document): . . . class Child1Document(ParentDocument): . .
I have the following classes and I need to know if DocPage class have
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)

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.