Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
There is a challenging problem with saving files is SQL.
I have a table and a list:
public Table<TableBuildResource> tableBuildResource = null;
public List<TableBuildResource> listBuildResource = null;

After I load sql data, I convert table to list.
For saving, I have to convert list to table. But, always there is problem with primary key, because although table records are deleted, adding those records again from list are assumed as error. The is no redundancy in the list due to primary key. but still there is problem with saving.

private void SaveBuildResource()
{
    var DelList = from c in tableBuildResource
                  select c;
    tableBuildResource.DeleteAllOnSubmit(DelList);
    foreach (TableBuildResource t in listBuildResource)
        tableBuildResource.InsertOnSubmit(t);
    SubmitChanges();
}






I use SQL-CE and linq-to-sql in C#.

What should I do?


Eddy Vluggen wrote:
You'd have to iterate your Table-List, updating every changed record.

It slows down the speed of program. Tables are much slower that Lists. Also it needs reflection(to work for all classes because my program has many classes that has to be saved in sql file). Also, it needs to a loop nested in another to check if a row exists or is new(too much slow for a long database. At least 10^6 checks!)

I wonder, if overwriting a row is so dispensable for SQL to be neglected?
Also I can solve the problem even if SQL consented to delete all rows and forgot them. But as if it is going to annoy people.
It is more funny when I googled and found no example of overwriting a row. In all samples the programmer just defined a new row and added manual data and then inserted the row. then saved and sometimes used complex flexibilities of linq-to-sql. But I found no simple practical sample. It looks like a joke.

The thing I am looking for is so easy. Why Linq Tables have such unfriendly manner?
Posted
Updated 17-Apr-10 2:56am
v4

1 solution

aasser wrote:
For saving, I have to convert list to table. But, always there is problem with primary key, because although table records are deleted, adding those records again from list are assumed as error.

Those would be considered "new records", and all associations with other records would be lost - because they are still pointing to the original PK-value.

You'd have to iterate your Table-List, updating every changed record.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900