Association(One to Many) + CRUD

6 posts, 0 answers
  1. Gaurav
    Gaurav avatar
    10 posts
    Member since:
    Feb 2012

    Posted 20 Mar 2012 Link to this post

    i have some issue with parent child insertion through ria service.

    i have 1 table

    Order

    Order_Id

    Order_er_Name

    Order_code

    Second table

    Order_Items

    Order_Item_Id

    Order_ID

    i have created entity model through telerik open access orm

    adiitional i have created metadata class for order with

    [Include]

    [Association("Order_OrderItems", "Order_ID", "Order_Id")]

    [DataMember]

    public IList<Order_Item> Order_items

    {

    get;

    set;

    }

    now if i m going to insert operation through service

    order o = new order()

    o.order_er_name = "MyName";

    o.order_code = "001)

    foreach(order_items oitem in list_Items)

    {

    o.order_items.ad(oitem);

    }

    service.orders.add(order)

    it will insert succesfully if there is only 1 order_item added in order

    and if i try to add more than 1 order_item and than trying to save

    service.orders.add(order)

    it gives error below.

    ------------------

    Submit operation failed. Insert of '1356035761-' failed: Telerik.OpenAccess.RT.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ORderItem_OrderId". The conflict occurred in database "IHC", table "dbo.Order", column 'Order_Id'.

    The statement has been terminated.

    at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()

    at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()

    at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)

    INSERT INTO [OrderItem] ([Changed_By_User], [Changed_On_Date], [Created_By_User], [Created_On_Date], [Currency_Id], [Markup_Calculation_Id], [Minimum_Value], [Order_Id], [Order_Code_Id], [Shipment_Denomination_Id], [Tax_Perc], [Use_Cost_Value], [Use_Flat_Selling_Rate], [Use_Markup_Perc], [Use_Markup_Value], [Use_Total_Perc]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

    select scope_identity()

    (set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_OrderItem_OrderId". The conflict occurred in database "IHC", table "dbo.Order", column 'Order_Id'.

    The statement has been terminated.

    at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()

    at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()

    at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) InnerException message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_OrderItem_OrderId". The conflict occurred in database "IHC", table "dbo.Order", column 'Order_Id'.

    The statement has been terminated.

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 23 Mar 2012 Link to this post

    H Gaurav,

     It seems like the foreign key is not correctly pushed down to the child objects and that is the reason why your insert is failing. Can you please check if your association has its managed property set to true? If it is not set can you please enable it for that association. I believe that this will fix your problem. Additional information regarding the managed property can be found here.

    All the best,
    Petar
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  3. DevCraft banner
  4. Gaurav
    Gaurav avatar
    10 posts
    Member since:
    Feb 2012

    Posted 23 Mar 2012 Link to this post

    thanks for reply.

    i have taken care about ismanged property and its true.
    so that is not the issue.

    because of IsManaged = true we are able to store single child table entry.

    i mean when we have single record in child object of parent entity object its inserted successfully with parent reference in child table automaticaly.

    another thing about this issue.
    i have resolved this issue only while Inseting new entry for parent table.

    by doing so
    ===================

    foreach(order_items oitem in list_Items)

    {
            oitem.Order = o;

            o.order_items.ad(oitem);

    }

    after this all order items added successfully. in both tables

    but while i am again going to edit that order and if i add/delete any child details than it gives error like below

    "Submit operation failed validation. Please inspect Entity.ValidationErrors for each entity in EntitiesInError for more information."

    =======================
    Regards,
    Gaurav
  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 27 Mar 2012 Link to this post

    Hello Gaurav,

     Have you tried specifying the parent manually for your second edit/add as well? We have created a similar application on our side and everything seems to work as expected so I am guessing its a configuration issue on your side.
    Also have you inspected the error message provided in the ValidationErrors collection and if you have, can you please share it with us?

    Greetings,
    Petar
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
  6. Gaurav
    Gaurav avatar
    10 posts
    Member since:
    Feb 2012

    Posted 06 Apr 2012 Link to this post

    Hello, Support Team

             Sorry, replying late.
             but there were not configuration issue over there.
             and send me all configurations settings which i need to check.

             i have another same situation in my development of project.

             In which we have Document table
             With the following fields,
                      Id
                      Object_Type_Id (type of Parent Entity)
                      Object_Id (Primary key of Parent Entity)
                      Document_title
                      Document

    now if i want to select multiple documents for multiple entities like 
               Order Wise Document
               Product Wise Document

            than how can i manage this virtual association at run time with CRUD operation for each ??

             Please suggest me any way..

    BR,
    Gaurav
  7. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 11 Apr 2012 Link to this post

    Hello Gaurav,

     There aren't any specific configuration you should look at besides the IsManaged property on all your collection. You need to make sure that it is set to true for all. If this does not work try specifying the object reference manually.

    I was not able to fully understand your scenario for your second question. What exactly are you trying to achieve? Do you want to query some orders and get them associated with their respective documents and you want to join that with querying some products as well?

    Kind regards,
    Petar
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top
DevCraft banner