Subsonic Simplerepository GetPaged;枚举问题
曾经,SimpleRepository 不支持枚举。如果您有一个带有 Enum 的 POCO 对象,它将无法正确持久化,您必须有一个要使用的支持变量,例如:
public enum Color
{
Red = 1,
Blue = 2
}
public class Car
{
[SubSonicIgnore]
public Color CarColor
{
get
{
return (Color)ColorMe;
}
set
{
ColorMe= (int)value;
}
}
public int ColorMe;
}
表中的名称必须是变量的名称,而不是枚举。
此问题已通过 github 上的最新补丁解决。
但是,我在尝试使用 GetPaged 时仍然遇到问题
var results = Db.GetPaged<Car>(1, 10);
抛出异常:
**Tests.Models.NewTests.SimplePagedSearch threw exception: System.InvalidCastException: Invalid cast from 'System.Int32' to 'Models.Car.Color**
此异常发生在
SubSonic.Extensions.Objects.ChangeTypeTo( 的第 95 行) C:\TEMP\subsonic\SubSonic.Core\Extensions\Objects.cs 中的对象值,类型 conversionType):第 95 行
At one point, SimpleRepository didn't support enums. If you had a POCO object with an Enum it wouldn't persist correctly, you had to have a backing variable which you would use eg:
public enum Color
{
Red = 1,
Blue = 2
}
public class Car
{
[SubSonicIgnore]
public Color CarColor
{
get
{
return (Color)ColorMe;
}
set
{
ColorMe= (int)value;
}
}
public int ColorMe;
}
The name in your table would then have to be the named of the variable, and not the enum.
This issue was resolved with a recent patch on github.
However, I'm still seeing issues when trying to use GetPaged
var results = Db.GetPaged<Car>(1, 10);
Throws an exception:
**Tests.Models.NewTests.SimplePagedSearch threw exception: System.InvalidCastException: Invalid cast from 'System.Int32' to 'Models.Car.Color**
This exception occurs at line 95 of
SubSonic.Extensions.Objects.ChangeTypeTo(Object value, Type conversionType) in C:\TEMP\subsonic\SubSonic.Core\Extensions\Objects.cs: line 95
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修补了 Subsonic.Extensions.Objects.ChangeTypeTo 第 95 行以包含此子句:
因此从 int32 到 Enum 的直接转换不再抛出异常
I patched Subsonic.Extensions.Objects.ChangeTypeTo line 95 to include this clause:
So a direct cast from int32 to Enum no longer throws and exception