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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:34+00:00 2026-06-17T18:23:34+00:00

I have the following classes in my model – but I cant get it

  • 0

I have the following classes in my model – but I cant get it to create tables the way I expect.

public class Task
{
    public int Id { get; set; }
    public string Description { get; set; }
    private readonly BindingList<Dependancy> _dependancies = new BindingList<Dependancy>();
    public virtual BindingList<Dependancy> Dependancies
    {
        get { return _dependancies; }
    }
}

public class Dependancy
{
    public int Id { get; set; }
    [Required]
    public virtual Task Task { get; set; }
    [Required]
    public virtual Task NeededTask { get; set; }
}

I want the Dependancy table just to contain the following fields;

Id,
Task_Id,
NeededTask_Id

however the generated one contains an extra Task_Id1 field

I have tried the following overide in the context class;

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
      modelBuilder.Entity<Dependancy>().HasRequired( p=>p.Task ).WithMany().WillCascadeOnDelete(false);
      modelBuilder.Entity<Task>().HasMany<Dependancy>(c => c.Dependancies).WithOptional().WillCascadeOnDelete(false);
    }

but the unwanted field is still created.

  • 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-17T18:23:35+00:00Added an answer on June 17, 2026 at 6:23 pm

    Entity framework does not know that Dependancy.Task and Task.Dependancies are paired, so it creates two foreign key fields, one for both associations. You have to tell EF that both associations are counterparts:

    modelBuilder.Entity<Dependancy>().HasRequired(p => p.Task)
        .WithMany(t => t.Dependancies).WillCascadeOnDelete(false);
    

    The other association can be defined by

    modelBuilder.Entity<Dependancy>().HasOptional(p => p.NeededTask)
        .WithMany().WillCascadeOnDelete(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes in my Model: public abstract class Entity : IEntity
Using: Glassfish 3.1.2, EclipseLink. I have the following three-classes JPA model: @Entity public class
I’m developing MVC application and I have following classes in my model: public class
Let's say I have the following two classes: package example.model; public class Model {
I have the following classes: public class ComplexType { public long? Code { get;
I have the following object model: class ObjectA{ public string Description {get;set;} } class
I have the following classes: public class Truck { public Wheel Wheel { get;
I have the following classes: public class Note { public string Text { get;
I have the following classes: package models; public class Test extends activejdbc.Model { }
I have the following classes: import play.db.ebean.Model; import javax.persistence.*; @Entity public class A extends

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.