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

Updating in ASP.NET with sub-objects

1 Answer 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sharbel Lutfallah
Top achievements
Rank 1
Sharbel Lutfallah asked on 15 Jan 2009, 05:32 PM
Does anyone know the best way to update an object that is being accessed at the ASP.NET page level through a BLL which in turn gets it from OA's datalayer?  To complicate the question, how best should I handle setting a sub-object of the update object?  So, if I have a Product object, and I have a subobject of Category type... i change the category to another one, usually I would just chang e the categoryID in the stored proc, but now it seems I have to get the whole object? (seems like a lot of round trips!)

Please comment on my whole updating process... it seems like a lot of manual setting of properties for nothing:

This is the test method at the page level:

protected void cmdTest_Click(object sender, EventArgs e) 
        { 
            JobRequirementParameter p = JobRequirementParameterUtility.GetByID(1); 
            p.JobDemandItem = JobDemandItemUtility.GetByID(2);//I have to make a round trip to get the demand object?? 
            p.JobRequirementItem = JobRequirementUtility.GetByID(1); // I have to make a roundtrip here too? 
            p.Description = "sometext"
            p.Code = "@code"
            p.DataTypeID = 1; 
            JobRequirementParameterUtility.Update(p); 
        } 

This is the BLL method that updates.. as you can see, i am setting the values of the parameters again in the BLL because otherwise i get runtime-errors from OA.

public static bool Update(JobRequirementParameter c) 
        { 
            using (IObjectScope scope = Scope.GetNewObjectScope()) 
            { 
                scope.Transaction.Begin(); 
                var b = (from cc in scope.Extent<JobRequirementParameter>() 
                         where cc.ParameterID == c.ParameterID 
                         select cc).Single(); 
                if (b != null
                { 
                    JobRequirementParameter bn = (JobRequirementParameter)b; 
 
                    b.Code = c.Code; 
                    b.DataTypeID = c.DataTypeID; 
                    b.Description = c.Description; 
                    var demandItem = (from d in scope.Extent<JobDemandItem>() 
                                     where d.DemandID==c.JobDemandItem.DemandID 
                                     select d).SingleOrDefault(); //Another round trip??????
                    b.JobDemandItem = demandItem; 
                    //b.JobRequirementItem = c.JobRequirementItem; (commented out for now)
                    b.Title = c.Title; 
 
                    scope.Transaction.Commit(); 
                    return true
                } 
                else 
                { 
                    return false
                } 
 
            } 
        } 

Keeping in mind that the CRUD examples in the KB article that I read, are simplistic examples that do not pass the object to a BLL, and do not deal with sub-objects, is this the 'right' way to do it?  Again, it seems like a heck of a lot of manual setting of properties.

Any help would be greatly appreciated!!


1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 19 Jan 2009, 11:50 AM
Hi Sharbel Lutfallah,

I think we addressed similar problem with the BLL methods in our previous conversation (TicketID: 184814). As for the sub-objects, they are being updated the same way as others. If you have any further questions, do not hesitate to contact us.

All the best,
Alexander
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Sharbel Lutfallah
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or