ServiceStack.OrmLite: Table 当 class 名称出现在不同命名空间时发生冲突
ServiceStack.OrmLite: Table collision when class name appears in different namespaces
当有两个 class 具有相同名称但在不同命名空间中时,ServiceStacks OrmLite 无法区分两者。例如:
Type type = typeof(FirstNameSpace.BaseModel);
using (IDbConnection db = _dbFactory.Open())
{
db.CreateTable(false, type); // Creates table "basemodel"
}
type = typeof(SecondNamespace.BaseModel);
using (IDbConnection db = _dbFactory.Open())
{
db.CreateTable(false, type); // Creates nothing as there already is a table 'basemodel', even though its a completely different object/class
}
有没有一种通用的、干净的方法来确保这个问题得到解决?
被迫唯一命名 classes 并不理想; .NET 中命名空间的一部分是对不同的 classes 进行分组和分类。此外,可能存在具有相同 class 名称的第三方程序集,无法为您更改。
有办法处理吗?
OrmLite 使用 Type 的名称作为 table 名称,因此您不能使用 2 个具有相同名称的不同 Type。
您需要重命名其中一种类型以避免冲突或使用 [Alias(“UseTableName”)] 属性告诉其中一种类型使用不同的 RDBMS Table名字.
当有两个 class 具有相同名称但在不同命名空间中时,ServiceStacks OrmLite 无法区分两者。例如:
Type type = typeof(FirstNameSpace.BaseModel);
using (IDbConnection db = _dbFactory.Open())
{
db.CreateTable(false, type); // Creates table "basemodel"
}
type = typeof(SecondNamespace.BaseModel);
using (IDbConnection db = _dbFactory.Open())
{
db.CreateTable(false, type); // Creates nothing as there already is a table 'basemodel', even though its a completely different object/class
}
有没有一种通用的、干净的方法来确保这个问题得到解决?
被迫唯一命名 classes 并不理想; .NET 中命名空间的一部分是对不同的 classes 进行分组和分类。此外,可能存在具有相同 class 名称的第三方程序集,无法为您更改。
有办法处理吗?
OrmLite 使用 Type 的名称作为 table 名称,因此您不能使用 2 个具有相同名称的不同 Type。
您需要重命名其中一种类型以避免冲突或使用 [Alias(“UseTableName”)] 属性告诉其中一种类型使用不同的 RDBMS Table名字.