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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:54:39+00:00 2026-05-29T14:54:39+00:00

I got the following codes: public class Trip { public int TripId { get;

  • 0

I got the following codes:

public class Trip
{
    public int TripId { get; set; }

    public int DriverId { get; set; }

    public string StartingPoint { get; set; }

    public string Destination { get; set; }

    public DateTime TimeDepart { get; set; }

    public int SeatAvailable { get; set; }

    public virtual Carpooler Carpooler { get; set; }

    public virtual ICollection<Passenger> Passengers { get; set; }
}

public class Driver
{
    public int DriverId { get; set; }

    public int TripId { get; set; }

    public virtual Trip Trip { get; set; }
}

public class Passenger
{
    public int PassengerId { get; set; }

    public int TripId { get; set; }

    public virtual Trip Trip { get; set; }
}

A model builder:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        //one-to-one between Trip and Carpooler
        modelBuilder.Entity<Trip>()
            .HasRequired(x => x.Carpooler)
            .WithRequiredDependent();
        modelBuilder.Entity<Carpooler>()
            .HasRequired(x => x.Trip)
            .WithRequiredPrincipal();
        base.OnModelCreating(modelBuilder);

        //zero or one-to-many between Trip and Passenger
        modelBuilder.Entity<Trip>()
        .HasOptional(x => x.Passengers);

        modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    }

A initializer:

Database.SetInitializer<LiveGreenContext>(new CarpoolTripInitializer());

And i get the following error:
Multiplicity is not valid in Role ‘Trip_Driver_Target’ in relationship ‘Trip_Driver’. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be *.

Any solution for the problem? 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-29T14:54:41+00:00Added an answer on May 29, 2026 at 2:54 pm

    Configure the relationship between Trip and Driver. There is a DriverId property in Trip which is not configured. If you intend to use this as a navigational property you need to configure that too.

    Some of the configuration were incomplete in your OnModelCreating method and are corrected.

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Driver>()
            .HasRequired(x => x.Trip)
            .WithMany()
            .HasForeignKey(x => x.TripId);
    
        //one-to-one between Trip and Carpooler
        modelBuilder.Entity<Trip>()
            .HasRequired(x => x.Carpooler)
            .WithRequiredDependent();
    
        modelBuilder.Entity<Carpooler>()
            .HasRequired(x => x.Trip)
            .WithRequiredPrincipal();
    
        //zero or one-to-many between Trip and Passenger
        modelBuilder.Entity<Trip>()
        .HasMany(x => x.Passengers)
        .WithRequired(x => x.Trip)
        .HasForeignKey(x => x.TripId);
    
        base.OnModelCreating(modelBuilder);
    
        modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class DTOa { public int Id { get; set;} public string FirstName {
I've got the following code: public IList<IProductViewModel> ChildProducts { get; set; } public IList<IProductViewModel>
Consider the following code: [Serializable] public class Human { public string Name { get;
I've got the following classes: public class SupplierCategory : IEquatable<SupplierCategory> { public string Name
I've got the following classes: public class ObjectCollection : List<ObjectRow> { public Dictionary<int, ObjectRow>
I got the following code : public class PluginShape : INotifyPropertyChanged { private string
I got the following piece of code: public class Collect { public string name{
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I've got the following code: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub
I've got following code in c# public class Shedluer { public delegate void TaskCompletedDelegate(ulong

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.