Asp – Advice on Subsonic Batch Insert Query

asp.net-mvcsubsonicsubsonic3

hi am running batch insert with subsonic 3.0.0.3 and MVC and i have wrote the following example:

var myquery1 = new Insert(provider).Into<orderitem>("orderitem_orderid", "orderitem_productid", "orderitem_qty", "orderitem_total",
                    "orderitem_sessionid", "orderitem_internal", "orderitem_measurement").Values("1", "1", "1", "0.00", "12345", "0", "1x1");
        batch.QueueForTransaction(myquery1);

        var myquery2 = new Insert(provider).Into<orderitem>("orderitem_orderid", "orderitem_productid", "orderitem_qty", "orderitem_total",
                    "orderitem_sessionid", "orderitem_internal", "orderitem_measurement").Values("2", "1", "1", "0.00", "12345", "0", "1x1");
        batch.QueueForTransaction(myquery2);

        batch.ExecuteTransaction();

this works and all is fine, however does anyone know how i can get away with not listing all the column names, but instead have some reference to the subsonic class for the table ???? and then simply have my values in the correct order.

the above works but seems a bit untidy, and i have much bigger tables than this too.

many thanks

Best Answer

It sounds like you want to be able to do something like:

var myquery1 = new Insert(provider).Into<orderitem>().Values("1", "1", "1", "0.00", "12345", "0", "1x1");

batch.QueueForTransaction(myquery1);

However this won't work and to be honest it's not really advisable either. The reason it won't work is that SubSonic won't know which values to map to which columns in your table. The reason I don't believe it's advisable is that any modification to the underlying tables could easily result in the values being inserted into unexpected columns and also the actual code is very opaque. It's all very well for someone with an intimate knowledge of the database but if you look at that code from a maintenance perspective it's impossible to easily tell what is actually happening.

EDIT: If you want intellisense for your column names you can do the following (check Structs.cs to see what gets generated automatically for your table/column names):

var myquery1 = new Insert(provider).Into<orderitem>(OrderItemTable.ProductIdColumn).Values("1");

batch.QueueForTransaction(myquery1);
Related Topic