orm 与实体框架 4 和代码优先

发布于 2024-10-01 07:12:09 字数 144 浏览 0 评论 0原文

我想编写一个库来将任何对象存储到数据库中。我仍然首先使用代码以及类 DbContextDbSet 来对已知对象进行映射。但在这种情况下,我不知道必须映射的对象的结构。有没有办法用上面的类来做到这一点?

I want to write a library to store any objects to a database. I still did the mapping for known objects using code first and the classes DbContext and DbSet. But in this case I don't know the structure of the objects I have to map. Is there a way to do this with the classes above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

-黛色若梦 2024-10-08 07:12:09

唯一的方法是动态创建映射类并将它们加载到 ORM 中,但我不确定 EF4 是否可以这样做,因为我是 NHibernate 人员。

顺便说一句,我看不出这背后的动机。为什么你需要这样的东西?

如果您需要存储具有不同(和未知)模式的对象,您可以使用关系数据库中的 TEXT 字段来使用序列化 LoB 模式 (http://martinfowler.com/eaaCatalog/serializedLOB.html),或者使用较少的模式NoSql 文档数据库,例如 MongoDB。

The only way you could do it is to create mapping classes dynamically and loading them into the ORM, but I'm not sure this is possible with EF4 since I'm a NHibernate guy.

By the way, I can't see a motive behind this. Why would you need such a thing?

If you need to store objects that have different (and unknown) schema you can use the Serialized LoB pattern (http://martinfowler.com/eaaCatalog/serializedLOB.html) using a TEXT field in a relational database or go schema less with a NoSql document database such as MongoDB.

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