0

I have a:

class Garage {
    int garageID;
    ISet<Car> cars
}

should the cars class have garageID as one of its properties, as in:

class Car {
   int carID;
   int garageID;
   String name;
}

That is how it appears in the database, but wondering if the classes on the many side are supposed to have the foreign key as a property or if the ORM just adds that in when performing the SQL (assuming you can specify it in the mappings file).

1 Answer 1

1

In short: No. (and yes the ORM will take care of FK based on your mapping files)

The "Car" table will have the GarageId in it but you should not add it to the Car class.

You can have a bi-directional relationship (although opinions vary on whether these are a good idea).

A bi-directional relationship would make the Car class look like this:

public class Car {
     public virtual int Id {get; set;}
     public virtual Garage Garage {get; set;}  //You can traverse back up to Garage
     public virtual string Name {get; set;}
}

If you would like me to post the Fluent/XML maps let me know.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.