Hi, I've just started to play around with DO.Net and wanted to create an one-to-one relationship between two classes (tables). Say, I have two entities, Course and price. A course can be linked to one or NO price. I want the key for price to be the CourseId. I don't want the course to have a foreign key to Price. So I created my model like this

public class Course : Entity
    [Field, Key]
    public long CourseId { get; private set; }

    public string Name { get; set; }

    public Price Price { get; set; }

public class Price: Entity
    [Field, Key]
    public Course Course { get; set; }

    public PriceType PriceType { get; set; }

I was expecting to have two tables in my DB, Course and Price, the primary key for Price being CourseId and no field referencing Price in Course table. However, after my domain is built, the table Course includes a field called 'Price.course'.

So my question is, Is there any way of creating this mapping between Course and Price where only Price references Course in the database? I can accomplish this if I have an EntitySet<price> in Course, but I want only one price to be linked to Course.

I've tried to use Association attribute, but I didn't succeed.

Any help? Thanks

asked Feb 06 '14 at 21:53

Jamal%20Lucas's gravatar image

Jamal Lucas

One Answer:

Hello Jamal,

unfortunately such mapping is not supported.

There is always a separate set of key columns for each reference field.

answered Feb 09 '14 at 02:38

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov

Thanks Denis!

(Feb 14 '14 at 10:54) Jamal Lucas Jamal%20Lucas's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA