精致的模型映射
我一直在使用 Dapper,我有一个问题。有没有办法让我能够在 POCO 类中拥有枚举器类型属性并使用 Dapper?似乎每次我添加 Enumerator 类型的属性时都会收到以下异常:
System.NotSupportedException:类型:*my_enum_type* 不是 由精致的支持
我在这里遗漏了什么吗?是否有一个属性可以附加到这些属性来指定其中哪些属性映射到数据库表列?
I've been playing with Dapper and I have a question. Is there a way for me to be able to have an enumerator type property in my POCO class and use Dapper? Seems like every time I add a property which is of type Enumerator I get the following exception:
System.NotSupportedException: The type : *my_enum_type* is not
supported by dapper
Am I missing something here? Is there an attribute that I can attach to these properties to specify which of them are mapping to database table columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 dapper 中的一个老错误,请确保您使用最新版本。 Dapper 过去对输入类型属性不执行任何过滤。
<罢工>
好吧,我明白了这一点,这是我的错,因为我一开始就没有看到这一点。这就是我最初所做的:
但需要做的是:
换句话说,将 param 声明为匿名类型是必不可少的。如果将 param 声明为特定类型,并且该类型包含 dapper 代码(例如 Enum)未涵盖的类型的属性,则代码会因上述错误而崩溃。我的 User 类有一个 Enum 类型属性,它导致了问题。
This is an old bug in dapper, ensure you use the latest version. Dapper used to perform no filtering on the input types properties.
Ok I figured this out and it was my fault for not seeing this in the 1st place. This is what I was doing initially:
But what needed to be done is:
In other words declaring param as anonymous type is essential. If you declare param as a specific type and that type contains a property of type which is not covered by dapper code (such as Enum) then the code crashes with the above mentioned error. My User class had an Enum type property and it was causing the problem.