开发者

What do these .NET auto-generated table adapter commands do? e.g. UPDATE/INSERT followed by a SELECT

开发者 https://www.devze.com 2022-12-26 17:02 出处:网络
I\'m working with a legacy application which I\'m trying to change so that it can work with SQL CE, whilst it was originally written against SQL Server.

I'm working with a legacy application which I'm trying to change so that it can work with SQL CE, whilst it was originally written against SQL Server.

The problem I am getting now is that when I try to do dataAdapter.Update, SQL CE complains that it is not expecting the SELECT keyword in the command text. I believe this is because SQL CE does not support batch SELECT statements.

The auto-generated table adapter command looks like this...

this._adapter.InsertCommand.CommandText = @"INSERT INTO [Table] ([Field1], [Field2]) VALUES (@Value1, @Value2);
SELECT Field1, Field2 FROM Table WHERE (Field1 = @Value1)";

What is it doing? It looks like it is inserting new records from the datatable into the database, and then reading that record back from the database into the datatable? What's the point of that?

Can I just go through the code and remove all these SELECT statements? Or is there an easier way to solve my problem of wanting to use these data adapters with SQL CE?

I cannot regenerate these table adapters, as the people who knew how to have long sin开发者_JS百科ce left.


It is just updating the object with the latest values from the database, after an update. Always seemed a little unecessary to me but hey...

These are a nuisance from a maintenance point of view - if you have the option, you'll save yourself a lot of hassle by abstracting this all out to a proper data layer.


allows that the field values might be altered by trigger(s) on the table. Sensible enough, I'd have thought, in auto-generated boilerplate.

though the select statement is a tad whacky to assume that field1 is the primary key... but maybe the autogen code makes sure it is before generating this bit of code.

0

精彩评论

暂无评论...
验证码 换一张
取 消