使用 Dapper 和具有复合键的数据库表生成动态 C# 类
我有一个具有组合键的数据库表。在我的 C# 代码中,我不使用域类,但根据数据库中配置的表名称,我读取该名称并生成 C# 域类。有没有人尝试过从具有组合键的配置表动态生成 C# 类?
例子: 假设我有一个 User
表,其中包含组合键、UserID
和 UserName
。我使用反射和 Dapper 在 C# 中动态生成 User
类。如何动态生成 User
类并将记录插入到 User
表中,该表现在需要 2 个值,UserID
和 UserName< /代码>?
I have a database table that has a composite key. In my C# code, I don't use Domain classes but based on the name of the table configured in the database, I read that and generate the C# domain class. Has anyone tried to dynamically generate a C# class from the configuration table that has a composite key?
Example:
Let's say I have a User
table with a composite key, UserID
and UserName
. I dynamically generate the User
class in C# using reflection and Dapper. How can I generate the User
class dynamically and insert a record into the User
table which now requires 2 values, UserID
and UserName
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于带有复合密钥的模型,我使用了属性[explicitkey]而不是[key]。
In the case of models with composite keys, I have used the attribute [ExplicitKey] instead of [Key].