Skip to content

Bug: Calling InsertAll With Map Attribute leads to System.NullReferenceException: 'Object reference not set to an instance of an object.' #274

@mikependon

Description

@mikependon

Model:

namespace RepoDbTest.Models
{
	public class Person
	{
		[Map("Id")]
		public int PersonId { get; set; }
		[Map("SSN")]
		public Guid SocialSecurityNumber { get; set; }
		[Map("Name")]
		public string CompleteName { get; set; }
		[Map("DateOfBirth")]
		public DateTime? DateOfBirth { get; set; }
		[Map("DateRegistered")]
		public DateTimeOffset DateRegistered { get; set; }
		public string LastUserId { get; set; }
		public string OtherProperty { get; set; }
	}
}

Code:

    private static void TestInsertAll()
    {
        var people = GetPeople();
        using (var connection = new SqlConnection(m_connectionString))
        {
            connection.InsertAll(people);
            var tableName = ClassMappedNameCache.Get<Person>();
            var fields = DbFieldCache
                .Get(connection, tableName)
                .Select(f => new Field(f.Name, f.Type));
            connection.InsertAll(tableName, people, fields: fields, trace: new CustomTrace());
        }
    }

Stack:

at RepoDb.Reflection.FunctionFactory.GetDataEntityPropertySetterFromDbCommandParameterFunction[TEntity](Field field, String parameterName, Int32 index)
at RepoDb.FunctionCache.GetDataEntityPropertySetterFromDbCommandParameterFunctionCache`1.Get(Field field, String parameterName, Int32 index)
at RepoDb.DbConnectionExtension.<>c__DisplayClass177_0`1.<InsertAllInternalBase>b__0(Int32 batchSizeValue)
at RepoDb.Contexts.Execution.InsertAllExecutionContextCache`1.Get(String tableName, IEnumerable`1 fields, Int32 batchSize, Func`2 callback)
at RepoDb.DbConnectionExtension.InsertAllInternalBase[TEntity](IDbConnection connection, String tableName, IEnumerable`1 entities, Int32 batchSize, IEnumerable`1 fields, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder, Boolean skipIdentityCheck)
at RepoDb.DbConnectionExtension.InsertAllInternal[TEntity](IDbConnection connection, IEnumerable`1 entities, Int32 batchSize, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
at RepoDbTest.Program.TestInsertAll() in C:\Users\MIPEN\source\repos\RepoDbTest\RepoDbTest\Program.cs:line 53
at RepoDbTest.Program.Main(String[] args) in C:\Users\MIPEN\source\repos\RepoDbTest\RepoDbTest\Program.cs:line 18

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions