Why can't I insert record with foregion key in a single server request?

Posted by Eran Betzalel on Stack Overflow See other posts from Stack Overflow or by Eran Betzalel
Published on 2010-05-24T08:06:56Z Indexed on 2010/05/24 8:11 UTC
Read the original article Hit count: 345

Filed under:
|
|

I'm tryring to do a simple insert with foregion key, but it seems that I need to use db.SaveChanges() for every record insert. How can I manage to use only one db.SaveChanges() at the end of this program?

foreach (var file in files)
{
    db.AddToFileSet(file);
    db.SaveChanges();

    db.AddToDirectorySet(
        new GlxCustomerPhone
        {
            SimIdentifier = file.Name + "Dir",
            CreationDate = DateTime.UtcNow,
            file_relation = file
        });
    db.SaveChanges();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .net-3.5