InsertAllOnSubmit only inserts the first data record

I noticed strange behavior in my import service today when I tried to import multiple data records.

When I do this like this, all data records are imported and the values ​​automatically increase ( see screenshot ):

public void Create(List<Property> properties)
{
    foreach (Property prop in properties) {
        dbc.Property.InsertOnSubmit(prop);
        dbc.SubmitChanges();
    }
}

When I try to do this, only the first data record gets the correct auto-increment value ( see screenshot ):

foreach (Property prop in properties) {
    dbc.Property.InsertOnSubmit(prop);
}
dbc.SubmitChanges();

Same:

dbc.Property.InsertAllOnSubmit(properties);
dbc.SubmitChanges();

Does anyone have an idea why this is so? All three options should import all data records in accordance with my understanding, but missing automatically increasing values ​​indicate that this is not so.

[EDIT] Added two screenshots.

+5
5

, , Equals . Equals , . , , 0. , InsertAllOnSubmit, , , .

+6

, , , :

dbc.Property.InsertallOnSubmit(properties);
dbc.SubmitChanges();

:

foreach (Property prop in properties) 
{   
    var newProp = new Property();
    newProp = prop;
    dbc.Property.InsertOnSubmit(newProp);
}
dbc.SubmitChanges();

:

dbc.Property.InsertAllOnSubmit(properties.ToList());
dbc.SubmitChanges();
+2

.

, , InsertAllOnSubmit<mappedClass>(), , mappedClass. , , .

, -, , - !

+1

Just use this, the perfect solution.
Like, We have a new object such as "TestTable".
Initialize this object inside the for loop as

TestTable objTable = new TestTable ();

And add the elements of the entity as well as to the list object from the list <TestTable>in the for loop.
And move InsertAllOnSubmit()over the for loop, and now it should work.

0
source

All Articles