This is a migrated thread and some comments may be shown as answers.

Diagram to databse structure..

1 Answer 43 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marchand
Top achievements
Rank 1
Marchand asked on 29 Nov 2010, 05:04 PM
Hi,

I try this sample :
- one object "User" with some propreties ID (auto-increment and primary key, Login, Level, Name, Mail).
- one object "Services" with some properties (Descrption).

I made a assiociation between this object :
- one user have some services
- one services have one user

==> I create my database schema...

==> and I play this code ....(see has follow)

            User o_User = new User();
            o_User.Login = "Login 1";
            o_User.Level = Common.Enums.e_User_Level.Operateur;
            o_User.Mail = "mail1";
            o_User.MDP = "*";

            Services o_Services = new Services();
            o_Services.Description= "Activité 1";
            o_User.Services.Add(o_Services);

            o_Services = new Services();
            o_Services.Description = "Activité 2";
            o_User.Services.Add(o_Services);

            o_Bll_Users.Add(o_User);

==> In my database there is no relation between table (key that be realized the relation is null)
==> can you explain to me why ?

For information, to obtain user key in the Services table, I am obliged to add this follow line :
            Services o_Services = new Services();
            o_Services.Description= "Activité 1";

==>     o_Services.User = o_User;    I think that is not obliged to add this line ?????? I don't know why, is it necesseray to add this line to obtain key in my database. I think that the line "o_User.Services.Add(o_Services);" is sufficient !

            o_User.Services.Add(o_Services);

            o_Services = new Services();
            o_Services.Description = "Activité 2";

==>     o_Services.User = o_User;


            o_User.Services.Add(o_Services);

            o_Bll_Users.Add(o_User);

In advance,
thanks
Richard.


1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 30 Nov 2010, 12:29 PM
Hi Marchand,

This behavior is observed because by default the associations created in the designer are not managed. An association to be managed means that you need to set only one of the relationship ends and the reference (or collection) on the other side will be updated automatically. If the association is not managed, you have to set both of the association ends like this:
Services o_Services = new Services();
o_Services.Description= "Activité 1";
//first end
o_User.Services.Add(o_Services);
//second end
o_Services.User = o_User;

However, if you define the association as managed you will not need this last line and can use your existing code without modifications. This option can be enabled from the Mapping Details Editor when the association is selected on the diagram. It should be enough just to check the Managed checkbox and save the model. Hope that helps.

Kind regards,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Getting Started
Asked by
Marchand
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or