linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
449 stars 39 forks source link

BulkCopy throws an Exception with ComplexProperty (Complex Type) #387

Open IT-CASADO opened 4 months ago

IT-CASADO commented 4 months ago

Following configuration throws an

Data.SqlClient.SqlException : Cannot insert the value NULL into column 'ColumnPropA', table 'IssuesEFCore.dbo.IssueXXXEntities'; column does not allow nulls. INSERT fails.

My Configuration:

    public readonly record struct MyComplexType(string PropA) { }

    public sealed class IssueXXXEntity
    {
        public required int Id { get; set; }

        public required string Name { get; set; }

        public MyComplexType MyComplexType { get; set; } = new MyComplexType("CT-1");
    }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<IssueXXXEntity>(b =>
            {
                b.HasKey(x => new { x.Id });

                b.ComplexProperty(
                    cp => cp.MyComplexType,
                    cp =>
                    {
                        cp.Property(p => p.PropA).HasColumnName("ColumnPropA");
                    }
                );
            });
        }

You can find a working repro here. Please run test with name Issue387Test

As a small reminder I changed the connection string for the IssueContext to a different SQL Server instance.