Skip to content

Commit

Permalink
+ Added IsComputed to PropertyMapping
Browse files Browse the repository at this point in the history
+ Set PropertyMapping.IsComputed for scalar properties based on prop.Column.IsStoreGenerated
+ Changed InsertAll and UpdateAll to skip computed columns
> Was unable to add proper tests as there does not appear to be a database creation script in the solution and I didn't feel like reverse engineering one
  • Loading branch information
jlikens committed Feb 1, 2016
1 parent b01ec62 commit 871d250
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel.DataAnnotations.Schema;

namespace EntityFramework.Utilities
{
Expand Down Expand Up @@ -116,6 +117,7 @@ public void InsertAll<TEntity>(IEnumerable<TEntity> items, DbConnection connecti

var properties = tableMapping.PropertyMappings
.Where(p => currentType.IsSubclassOf(p.ForEntityType) || p.ForEntityType == currentType)
.Where(p => p.IsComputed == false)
.Select(p => new ColumnMapping { NameInDatabase = p.ColumnName, NameOnObject = p.PropertyName }).ToList();
if (tableMapping.TPHConfiguration != null)
{
Expand Down Expand Up @@ -157,6 +159,7 @@ public void UpdateAll<TEntity>(IEnumerable<TEntity> items, Action<UpdateSpecific

var properties = tableMapping.PropertyMappings
.Where(p => currentType.IsSubclassOf(p.ForEntityType) || p.ForEntityType == currentType)
.Where(p => p.IsComputed == false)
.Select(p => new ColumnMapping {
NameInDatabase = p.ColumnName,
NameOnObject = p.PropertyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class PropertyMapping
public bool IsPrimaryKey { get; set; }

public string DataTypeFull { get; set; }
public bool IsComputed { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -155,7 +156,7 @@ public EfMapping(DbContext db)
tableMapping.Schema = mappingToLookAt.Fragments[0].StoreEntitySet.Schema;
tableMapping.TableName = mappingToLookAt.Fragments[0].StoreEntitySet.Table ?? mappingToLookAt.Fragments[0].StoreEntitySet.Name;
typeMapping.TableMappings.Add(tableMapping);

Action<Type, System.Data.Entity.Core.Mapping.PropertyMapping, string> recurse = null;
recurse = (t, item, path) =>
{
Expand All @@ -176,7 +177,8 @@ public EfMapping(DbContext db)
DataType = scalar.Column.TypeName,
DataTypeFull = GetFullTypeName(scalar),
PropertyName = path + item.Property.Name,
ForEntityType = t
ForEntityType = t,
IsComputed = scalar.Column.IsStoreGeneratedComputed
});
}
};
Expand Down

0 comments on commit 871d250

Please sign in to comment.