Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
*.user
/Tanneryd.BulkOperations.EF6/Tanneryd.BulkOperations.EF6.Tests/EF/StebbingContext.cs
Tanneryd.BulkOperations.EF6/Tanneryd.BulkOperations.EF6.NetStd/nuget_api.txt
/Tanneryd.BulkOperations.EF6/issue-31-reproduction/bin/Debug
/Tanneryd.BulkOperations.EF6/issue-31-reproduction/obj
6 changes: 6 additions & 0 deletions Tanneryd.BulkOperations.EF6/Tanneryd.BulkOperations.EF6.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tanneryd.BulkOperations.EF6
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tanneryd.BulkOperations.EF6.Tests", "Tanneryd.BulkOperations.EF6.Tests\Tanneryd.BulkOperations.EF6.Tests.csproj", "{82605BC1-B02B-4ED6-94E0-864D673BAEE9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "issue-31-reproduction", "issue-31-reproduction\issue-31-reproduction.csproj", "{815A6214-68DF-48E0-8DC8-3446AB939634}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{82605BC1-B02B-4ED6-94E0-864D673BAEE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82605BC1-B02B-4ED6-94E0-864D673BAEE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82605BC1-B02B-4ED6-94E0-864D673BAEE9}.Release|Any CPU.Build.0 = Release|Any CPU
{815A6214-68DF-48E0-8DC8-3446AB939634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{815A6214-68DF-48E0-8DC8-3446AB939634}.Debug|Any CPU.Build.0 = Debug|Any CPU
{815A6214-68DF-48E0-8DC8-3446AB939634}.Release|Any CPU.ActiveCfg = Release|Any CPU
{815A6214-68DF-48E0-8DC8-3446AB939634}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2316,11 +2316,12 @@ private static Mappings GetMappings(DbContext ctx, Type t)
//
var foreignKeyMappings = new List<ForeignKeyMapping>();
var navigationProperties =
typeMapping.EntityType.DeclaredMembers
.Where(m => m.BuiltInTypeKind == BuiltInTypeKind.NavigationProperty)
.Cast<NavigationProperty>()
.Where(p => p.RelationshipType is AssociationType)
.ToArray();
typeMapping.EntityType
.DeclaredMembers
.Where(m => m.BuiltInTypeKind == BuiltInTypeKind.NavigationProperty)
.Cast<NavigationProperty>()
.Where(p => p.RelationshipType is AssociationType)
.ToArray();

foreach (var navigationProperty in navigationProperties)
{
Expand Down
18 changes: 18 additions & 0 deletions Tanneryd.BulkOperations.EF6/issue-31-reproduction/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>

88 changes: 88 additions & 0 deletions Tanneryd.BulkOperations.EF6/issue-31-reproduction/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using issue_31_reproduction.dbmodel;
using Tanneryd.BulkOperations.EF6.NetStd;

namespace issue_31_reproduction
{
class Program
{
static void Main(string[] args)
{
try
{
string dbName = "issue31repro";
string dataSource = "(localdb)\\MSSQLLocalDB";
//string dataSource = "localhost\\SQLEXPRESS";

string connStrFormat = $"Data Source={dataSource};Initial Catalog={{0}};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
EnsureLocalDb(connStrFormat, dbName);
var dbModel = new DbModelContainer($"metadata=res://*/dbmodel.DbModel.csdl|res://*/dbmodel.DbModel.ssdl|res://*/dbmodel.DbModel.msl;provider=System.Data.SqlClient;provider connection string='{string.Format(connStrFormat, dbName)}'");
var logItems = new List<LogItem>()
{
CreateLogItemInstance(),
CreateLogItemInstance(),
CreateLogItemInstance()
};
Console.WriteLine($"Before bulk insert - Table Log contains {dbModel.Log.Count()} items");
dbModel.BulkInsertAll(logItems);
Console.WriteLine($"After bulk insert - Table Log contains {dbModel.Log.Count()} items");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}

static void EnsureLocalDb(string connStringFormat, string dbName)
{
ExecQuery(string.Format(connStringFormat, "master"), $"If(db_id(N'{dbName}') IS NULL) BEGIN CREATE DATABASE [{dbName}]; END; ");
ExecQuery(string.Format(connStringFormat, dbName), System.IO.File.ReadAllText("create_script.sql"));
}

static void ExecQuery(string connString, string query)
{
using (SqlConnection connection = new SqlConnection(
connString))
{
SqlCommand command = new SqlCommand(
query, connection);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
}
}

static LogItem CreateLogItemInstance()
{
return new LogItem()
{
ConfigId = DateTime.UtcNow.Ticks,
Exception = "my exception",
Message = "my message",
CorrelationId = Guid.NewGuid(),
CrmUser = Guid.NewGuid(),
Date = DateTime.UtcNow,
EntityId = Guid.NewGuid(),
EntityLogicalName = "myentity",
Level = "DEBUG",
Logger = "Db integration test",
OrganizationId = Guid.NewGuid(),
SdkMessage = "TestMessage",
Thread = "1",
Id = 0
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("issue-31-reproduction")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("issue-31-reproduction")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("815a6214-68df-48e0-8dc8-3446ab939634")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

IF OBJECT_ID(N'[dbo].[Log]', 'U') IS NOT NULL
DROP TABLE [dbo].[Log];

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Log'
CREATE TABLE [dbo].[Log] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[Date] datetime NOT NULL,
[Thread] nvarchar(255) NOT NULL,
[Level] nvarchar(50) NOT NULL,
[Logger] nvarchar(255) NOT NULL,
[Message] nvarchar(4000) NOT NULL,
[Exception] nvarchar(2000) NULL,
[EntityId] uniqueidentifier NULL,
[EntityLogicalName] nvarchar(100) NULL,
[ConfigId] bigint NOT NULL,
[SdkMessage] nvarchar(20) NULL,
[CrmUser] uniqueidentifier NULL,
[CorrelationId] uniqueidentifier NULL,
[OrganizationId] uniqueidentifier NULL
);

-- Creating primary key on [Id] in table 'Log'
ALTER TABLE [dbo].[Log]
ADD CONSTRAINT [PK_Log]
PRIMARY KEY CLUSTERED ([Id] ASC);
Loading