提交 1e8011ce 编写于 作者: M Martin Devillers 提交者: Nick Craver

FIX: Properties of type Table<T, TId> are not initialized

Table properties that implement Table<T,TId> instead of Table<T> are not recognized during the initialization of the Database<T> class. As a result, these properties remain uninitialized after the call to Database<T>.Init().

// Works fine
public Table<Person> Persons { get; set; }

// Remains 'null' after Init
public Table<Car, Guid> Cars { get; set; }
上级 da7f0dd3
......@@ -177,7 +177,7 @@ internal void InitDatabase(DbConnection connection, int commandTimeout)
internal virtual Action<TDatabase> CreateTableConstructorForTable()
{
return CreateTableConstructor(typeof(Table<>));
return CreateTableConstructor(typeof(Table<>), typeof(Table<,>));
}
public void BeginTransaction(IsolationLevel isolation = IsolationLevel.ReadCommitted)
......@@ -197,13 +197,13 @@ public void RollbackTransaction()
transaction = null;
}
protected Action<TDatabase> CreateTableConstructor(Type tableType)
protected Action<TDatabase> CreateTableConstructor(params Type[] tableTypes)
{
var dm = new DynamicMethod("ConstructInstances", null, new Type[] { typeof(TDatabase) }, true);
var il = dm.GetILGenerator();
var setters = GetType().GetProperties()
.Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == tableType)
.Where(p => p.PropertyType.IsGenericType && tableTypes.Contains(p.PropertyType.GetGenericTypeDefinition()))
.Select(p => Tuple.Create(
p.GetSetMethod(true),
p.PropertyType.GetConstructor(new Type[] { typeof(TDatabase), typeof(string) }),
......@@ -340,4 +340,4 @@ public void Dispose()
}
}
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册