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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:16:05+00:00 2026-05-20T01:16:05+00:00

I Have two tables: Users and News. Table News has columns id, name, createdby,

  • 0

I Have two tables:

Users and News. Table News has columns id, name, createdby, modifiedby. Table user has columns id and name. Table News references table User by foreign keys createdby and modifiedby. I use
Entity Framework 4 ctp5. I tried to access createdby or modifiedby properties, but error appers: Invalid column name “UserId1”, Invalid column name “UserId2”. Could anybody explain what I am doing wrong?

public class News
{
    // Primitive properties

    public int ID { get; set; }
    public string Name { get; set; }
    public System.Guid UserId { get; set; }
    public System.Guid UserId1 { get; set; }

    // Navigation properties

    public virtual User User { get; set; }
    public virtual User User1 { get; set; }

}

public class User
{
    public int ID { get; set; }
    public string Name { get; set; }
}

public partial class SomeEntities : DbContext
{
    public SomeEntities() : base("name=SomeEntities"){ }

    public DbSet<User> Users { get; set; }
    public DbSet<News> News { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<News>().Property(i => i.UserId).HasColumnName("CreatedBy");
        modelBuilder.Entity<News>().Property(i => i.UserId1).HasColumnName("ModifiedBy");
    }
}
  • 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-20T01:16:06+00:00Added an answer on May 20, 2026 at 1:16 am

    The following object model gives you the desired results (I renamed properties just to make it more readable):

    public class News
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public Guid CreatedBy { get; set; }
        public Guid ModifiedBy { get; set; }
        public virtual User CreatedByUser { get; set; }
        public virtual User ModifiedByUser { get; set; }
    }
    
    public class User
    {
        public Guid ID { get; set; }
        public string Name { get; set; }
    }
    
    public class Ctp5Context : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<News> News { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<News>()
                        .HasRequired(n => n.CreatedByUser)
                        .WithMany()
                        .HasForeignKey(n => n.CreatedBy);
    
            modelBuilder.Entity<News>()
                        .HasRequired(n => n.ModifiedByUser)
                        .WithMany()
                        .HasForeignKey(n => n.ModifiedBy)
                        .WillCascadeOnDelete(false);                        
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables users registered_members I want to confirm values from user table
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I have two tables: Users and Files . Users table has 10 rows, Files
I have two tables users and *activation_details* Users table has these data. uid is
Assuming I have two tables: users and orders . A user has many orders,
I have two tables in my database: NEWS table with columns: id - the
I have two classes: User : /** @Entity @Table(name=users) */ class User { /**
I have two tables users with columns: uid, name, mail, etc users_roles with columns:
I have two tables with these columns: Users: user, class, grade, location. Classes: class,
I have two tables: COMMENTS and USERS . I save user's name on COMMENTS

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.