精致的模型映射

发布于 2024-11-25 16:12:28 字数 320 浏览 2 评论 0原文

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-12-02 16:12:28

这是 dapper 中的一个老错误,请确保您使用最新版本。 Dapper 过去对输入类型属性不执行任何过滤。

<罢工>
好吧,我明白了这一点,这是我的错,因为我一开始就没有看到这一点。这就是我最初所做的:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New User With {.UserID = userID})

但需要做的是:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New With {.UserID = userID})

换句话说,将 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:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New User With {.UserID = userID})

But what needed to be done is:

Dim result = conn.Query("SELECT * FROM Users WHERE UserID = @UserID", New With {.UserID = userID})

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文