diff --git a/EntityFramework.Utilities/EntityFramework.Utilities/EFBatchOperation.cs b/EntityFramework.Utilities/EntityFramework.Utilities/EFBatchOperation.cs index 72fa98c..033f6c9 100644 --- a/EntityFramework.Utilities/EntityFramework.Utilities/EFBatchOperation.cs +++ b/EntityFramework.Utilities/EntityFramework.Utilities/EFBatchOperation.cs @@ -9,6 +9,7 @@ using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; +using System.ComponentModel.DataAnnotations.Schema; namespace EntityFramework.Utilities { @@ -116,6 +117,7 @@ public void InsertAll(IEnumerable 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) { @@ -157,6 +159,7 @@ public void UpdateAll(IEnumerable items, Action currentType.IsSubclassOf(p.ForEntityType) || p.ForEntityType == currentType) + .Where(p => p.IsComputed == false) .Select(p => new ColumnMapping { NameInDatabase = p.ColumnName, NameOnObject = p.PropertyName, diff --git a/EntityFramework.Utilities/EntityFramework.Utilities/MappingHelper.cs b/EntityFramework.Utilities/EntityFramework.Utilities/MappingHelper.cs index 1100b1a..fc1a12c 100644 --- a/EntityFramework.Utilities/EntityFramework.Utilities/MappingHelper.cs +++ b/EntityFramework.Utilities/EntityFramework.Utilities/MappingHelper.cs @@ -94,6 +94,7 @@ public class PropertyMapping public bool IsPrimaryKey { get; set; } public string DataTypeFull { get; set; } + public bool IsComputed { get; set; } } /// @@ -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 recurse = null; recurse = (t, item, path) => { @@ -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 }); } };