Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CommandBuilder vs Stored Proc for updating
Message
 
 
À
25/01/2010 13:50:59
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01445437
Message ID:
01445867
Vues:
24
Thank you so much, Bonnie. I just read your reply and I already have more questions. But what I will do is read your message a couple of more times to see if I can figure out answers myself (I hate to take so much of your time. And always feel free to PM me with simple word "Unsubscribe" in the Title <g> and I will leave you alone).

>>1. Why do you create strings ChangedXML and DeletedXML if you still pas the datasets (dsChanged and dsDeleted) to the Web Service SAVE method? (I presume that if I don't use web service I would call some SAVE method of my DAL, right?)
>
>Damn! I screwed up ... that's what I get for posting code off the top of my head without the benefit of morning caffeine having properly kicked in. Sorry Dmitry, the Save() method should have been like this:
>
>
>MyWebService.Save(ChangedXML, DeletedXML);
>
>
>>And I don't want to pass the entire dataset to my DAL (my dataset could be fairly large, e.g. table with 1000 rows).
>
>No, you wouldn't be doing this ... even if you didn't do it the XML way, you'd use the DataSet.GetChanges() method to only pass the changes. That part doesn't change at all.
>
>>2. What do you do with the data sets dsChanged and dsDeleted in the SAVE method of your web service (and supposedly in the DAL)? Conceptually?
>
>
>1) The Web Service Save() method would put the XML back into the appropriate DataSets using the ReadXml() method of the DataSet. I use a FillWithXml() method, which could be a DataSet extension method (off the top of my head, watch out <g>):
>
>
>public static void FillWithXml(this DataSet ds, string XML)
>{
>    StringReader sr = new StringReader(XML);
>    ds.ReadXml(sr, XmlReadMode.InferSchema);
>    ds.AcceptChanges();
>}
>
>// since the above is an extension method for DataSets, you would use it like this server-side to "reconstitute" the DataSets:
>MyDataSet dsChanged = new MyDataSet();
>MyDataSet dsDeleted = new MyDataSet();
>dsChanged.FillWithXml(ChangedXML);
>dsDeleted.FillWithXml(DeletedXML);
>
>
>2) Then you'd pass those DataSets to the DAL (or preferably the Biz) Save() method.
>
>3) The DAL Save method would iterate through the rows in each table and call methods to populate the Parameter collection and call the appropriate Stored Procs, all which has been mentioned in previous posts.
>
>Hope that helps a bit more.
>
>~~Bonnie
>
>
>>First, thank you very much for the detailed explanation.
>>
>>I don't use web service but still would like to learn to do things the most efficient way (since I am sure in the future I will have different applications).
>>
>>And I don't want to pass the entire dataset to my DAL (my dataset could be fairly large, e.g. table with 1000 rows).
>>
>>A couple of things are not clear to me:
>>
>>1. Why do you create strings ChangedXML and DeletedXML if you still pas the datasets (dsChanged and dsDeleted) to the Web Service SAVE method? (I presume that if I don't use web service I would call some SAVE method of my DAL, right?)
>>
>>2. What do you do with the data sets dsChanged and dsDeleted in the SAVE method of your web service (and supposedly in the DAL)? Conceptually?
>>
>>Again, thank you.
>>
>>>It probably only matters if you're doing something a bit different. I'll show you what I mean with an example:
>>>
>>>I used web service methods to communicate with the backend. In doing so, the data that needed to update the database was passed as an XML string over the wire. In order to do this with the smallest XML footprint (IOW, not by using a diffgram), I proceeded in this manner:
>>>
>>>
>>>DataSet dsChanged = ds.GetChanges();
>>>DataSet dsDeleted = ds.GetChanges(DataRowState.Deleted);
>>>
>>>string ChangedXML = dsChanged.GetXml();
>>>dsDeleted.RejectChanges(); // necessary, otherwise you will get no XML
>>>string DeletedXML = dsDeleted.GetXml();
>>>
>>>MyWebService.Save(dsChanged, dsDeleted);
>>>
>>>
>>>Now, because I'm passing XML in this manner, I've lost the row state. IOW, when these XML strings are re-serialized server-side into a ChangedDataSet and a DeletedDataSet, since this XML (done in this manner) contains no row state, neither will the new server-side DataSets. I rely on PKs < =0 to indicate an added row, everything else is an update. And obviously, everything contained in the DeletedDataSet will be deleted rows.
>>>
>>>The above methodology would not work with the DataAdapter.Update() method for obvious reasons.
>>>
>>>The only way to use the DataAdapter.Update() is to have passed data that contains the row state, which means passing the DataSet itself to your server-side Save() method. Going over a web service, I think that .NET will automatically serialize the DataSet into XML for you, but it's serialized into a DiffGram which has a much, *much* larger footprint than what I outlined above. At any rate, I don't recommend sending a DataSet in this manner over a web service. If you're not using a web service, then that's a different matter.
>>>
>>>Anyway, I hope that cleared it up a bit.
>>>
>>>~~Bonnie
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform