Diagram to databse structure..

2 posts, 0 answers
  1. Marchand
    Marchand avatar
    15 posts
    Member since:
    Sep 2008

    Posted 29 Nov 2010 Link to this post


    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_Services = new Services();
                o_Services.Description = "Activité 2";


    ==> 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_Services = new Services();
                o_Services.Description = "Activité 2";

    ==>     o_Services.User = o_User;



    In advance,

  2. Alexander
    Alexander avatar
    727 posts

    Posted 30 Nov 2010 Link to this post

    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
    //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,
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  3. DevCraft banner
Back to Top