none
Mask Detail Relationship Tables RRS feed

  • Question

  • I have 4 related tables, they have a master-detail relationship as follow

    HotelCost and HotelCostItem have a one-many relationship

    Country(1)-------(n)Area(1)--------(n)City(1)-----------(n)Region

       //ConfirmClosing();
    
        List<ref_country> newcountrys = new List<ref_country>();
    
        List<ref_area> newareas = new List<ref_area>();
    
        List<ref_city> newcitys = new List<ref_city>();
    
        List<ref_region> newregions = new List<ref_region>();
    
        ref_region newregion1 = new ref_region();
    
        ref_region newregion2 = new ref_region();
    
        newregion1.EngName = "new region1";
    
        newregion2.EngName = "new region2";
    
        newregions.Add(newregion1);
    
        ref_city newcity = new ref_city();
    
        newcity.CityCode = "new";
    
        newcity.EngName = "gz";
    
        newcitys.Add(newcity);
    
        ref_area newarea = new ref_area();
    
        newarea.EngName = "new area";
    
        newarea.ChinaName = "teset";
    
        newareas.Add(newarea);
    
        ref_country newcountry = new ref_country();
    
        newcountry.EngName = "new country";
    
        newcountry.ChinaName = "测试";
    
        newcountry.CountryCode = "TE";
    
        newcountry.ref_area = newareas.ToArray();
    
        
    
        newcountrys .Add (newcountry);
    
        m_ref.refcountry = newcountrys.ToArray();
    
        m_context.UpdateReferences(m_ref);
    
    
    How do I make this work,  all I have to do is to update the master Country.
    Sunday, June 13, 2010 3:54 AM

Answers

  • Hello,

    Take the Country and Area for example, you could update the country like below:

     ===============================

    List<Area> areaList = new List<Area>();
    areaList.Clear();
    
    // add items in areaList;
    // ....
    
    // add areas in Area entity
    context.Area.InsertAllOnSubmit(areaList);
    // save the changes into database
    context.SubmitChanges();

    ===============================

    To Update an entity, you need to select it out first and then modify it. For example:

    var area = context.Area.Single(c => c.ID== 10);
    area.Name = "Modified name.";
    db.SubmitChanges();

    Please have a try and let me know if this help.
    If there are any questions, please don't hesitate and post here.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Thursday, June 17, 2010 10:04 AM