views:

25

answers:

1

I have an import, from flat file to an EDM against SQL Server, where very few records actually change (running it the umpteenth time with the same import file), but nonetheless the SaveChanges call to update 500 records takes quite long. I'm guessing this is because I set each property on the entity object, and EF then uses ReportPropertyChanged to signal that the record must be updated in the DB.

Do I actually have to compare all import recort property values to entity property values, and only assign to the entity property when they differ, to avoid these lengthy 'do-nothing' updates?

EDIT: The generated code for the setter for the Updated property looks like below. I can see the assignment is unconditional, which is why I'm asking if the actual generation of an UPDATE statement to the DB is conditional or not.

set
{
    OnUpdatedChanging(value);
    ReportPropertyChanging("Updated");
    _Updated = StructuralObject.SetValidValue(value);
    ReportPropertyChanged("Updated");
    OnUpdatedChanged();
}
+2  A: 

Do you use generated entity code? It already checks if value is same:

[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 Id
{
    get
    {
        return _Id;
    }
    set
    {
        if (_Id != value)
        {
            OnIdChanging(value);
            ReportPropertyChanging("Id");
            _Id = StructuralObject.SetValidValue(value);
            ReportPropertyChanged("Id");
            OnIdChanged();
        }
    }
}
private global::System.Int32 _Id;
partial void OnIdChanging(global::System.Int32 value);
partial void OnIdChanged();
Ladislav Mrnka
@Ladislav, please see my edit. The code generated for me does not have the guard. I am targetting .NET 4.0
ProfK