Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Dec 6, 2021
1 parent 9db26bd commit 57d1ec9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,22 @@ private bool PrepareForAdd(EntityState newState)

private void SetEntityState(EntityState oldState, EntityState newState, bool acceptChanges, bool modifyProperties)
{
var entityType = EntityType;

// Prevent temp values from becoming permanent values
if (oldState == EntityState.Added
&& newState != EntityState.Added
&& newState != EntityState.Detached)
{
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var property in EntityType.GetProperties())
foreach (var property in entityType.GetProperties())
{
if (property.IsKey() && HasTemporaryValue(property))
{
throw new InvalidOperationException(
CoreStrings.TempValuePersists(
property.Name,
EntityType.DisplayName(), newState));
entityType.DisplayName(), newState));
}
}
}
Expand All @@ -255,10 +257,10 @@ private void SetEntityState(EntityState oldState, EntityState newState, bool acc
if (newState == EntityState.Modified
&& modifyProperties)
{
_stateData.FlagAllProperties(EntityType.PropertyCount(), PropertyFlag.Modified, flagged: true);
_stateData.FlagAllProperties(entityType.PropertyCount(), PropertyFlag.Modified, flagged: true);

// Hot path; do not use LINQ
foreach (var property in EntityType.GetProperties())
foreach (var property in entityType.GetProperties())
{
if (property.GetAfterSaveBehavior() != PropertySaveBehavior.Save)
{
Expand All @@ -275,7 +277,7 @@ private void SetEntityState(EntityState oldState, EntityState newState, bool acc
if (newState == EntityState.Unchanged)
{
_stateData.FlagAllProperties(
EntityType.PropertyCount(), PropertyFlag.Modified,
entityType.PropertyCount(), PropertyFlag.Modified,
flagged: false);
}

Expand Down Expand Up @@ -318,7 +320,7 @@ private void SetEntityState(EntityState oldState, EntityState newState, bool acc
|| newState == EntityState.Detached)
&& HasConceptualNull)
{
_stateData.FlagAllProperties(EntityType.PropertyCount(), PropertyFlag.Null, flagged: false);
_stateData.FlagAllProperties(entityType.PropertyCount(), PropertyFlag.Null, flagged: false);
}

if (oldState == EntityState.Detached
Expand All @@ -339,7 +341,7 @@ private void SetEntityState(EntityState oldState, EntityState newState, bool acc

FireStateChanged(oldState);

HandleSharedIdentityEntry(oldState, newState, EntityType);
HandleSharedIdentityEntry(oldState, newState, entityType);

if ((newState == EntityState.Deleted
|| newState == EntityState.Detached)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
innerMethodCall,
(target, nullable) =>
{
var propertyType = methodCallExpression.Type;
if (nullable && !propertyType.IsNullableType())
{
propertyType.MakeNullable();
}
var indexerExpression = Expression.Call(
target,
methodCallExpression.Method, methodCallExpression.Arguments[0]);
Expand Down

0 comments on commit 57d1ec9

Please sign in to comment.