问题描述
这是纯粹与EF4的概念和设计理念。
This is purely a conceptual and design idea related to EF4.
这个例子/场景是一个大型的ERP或CRM型系统,企业可能需要添加传统的用户定义字段来捕获更多数据。
The example/scenario is a large ERP or CRM type system where companies may need to add traditional "user defined fields" to capture additional data.
我知道EF有一定的能力模型推送到数据库在运行时间,但真正的问题是,您可以使用EF修改模型和实时更新数据存储?
I know that the EF has some capabilities to push out the model to a database at run-time but the question really is can you use EF to modify a model and update the data store in real-time?
在换句话说,如果我给用户提供一种机制来添加一个用户定义的列,相关的数据类型和空要求,可以说是对与EF实时进行,然后又想起所有会话?
In other words, if I provide the user a mechanism to add a user defined column, associated data type and null requirements can that be done on the fly with EF and then remembered for all future sessions?
这是在那里,但我想大家会看到我得到的。
It's out there but I think you all will see what I'm getting at.
布伦特
推荐答案
我一直在问这个问题了几次了过去。没有明显的或简单的方法。这有可能是没有办法,但是我们是开发商和总有办法!我知道那是什么?不,我能想到的一些想法? ....嗯..在运行时,该模型被从metadataworkspace基于强类型的类。您可以创建这些上飞。但是你需要修改EDMX file.There的LINQ的XML到XML或XPath为。修改数据库架构...如何模式先建DBS ......它创建的SQL,然后执行它。你必须创建SQL(怎么样?耸肩)和执行它(objectcontext.executestorecommand())。可行?可能?我没有任何线索。真正的答案是否定的......有没有在VS或.NET 4(EF API)来随时启用此,据我所知。肯定有人更聪明和耐心,比我花了(浪费?)大量的时间(试图)智取EF拉这一关。根据,但是,你的反应吨重Jeremy的博客文章建议,你正在寻找的东西内置/得心应手。这很容易用不。
I've been asked this question a few times in the past. There is no obvious or easy way. It's possible that there is no way but we are developers and there's always a way! Do I know what that is? No. Can I dream up some ideas? ....Mmmm.. at runtime, the model is based on strongly typed classes from the metadataworkspace. You can create those on the fly. But then you need to modify the xml of the edmx file.There's LINQ to XML or xpath for that. Modifying the database schema... how does model first build dbs...it creates sql and then you execute it. You'd have to create sql (how? shrug) and the execute it (objectcontext.executestorecommand()). Feasible? Possible? I have no clue. Really the answer is no...there's nothing in VS or .NET 4 (EF APIs) to readily enable this as far as I know. Surely someone more clever and patient than I was spent (wasted??) a lot of time (trying to) outsmart EF to pull this off. Based, however, on your response t the suggestion re Jeremy's blog post, you're looking for something built in/handy. That is easier to answer with a "nope".
朱莉
这篇关于修改在运行时的实体框架模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!