实体框架/WCF——安全/智能地将entityObjects发送到Silverlight客户端?
我在这里有点困惑。
我使用从数据库建模的实体框架创建了 POCO 类。
显然,我也想在客户端中使用这些类(如果我想将它们发回并重新附加,那么对它们进行任何簿记都会很好)
我查看了为 WCF 服务引用生成的类,它通过互联网发送似乎有点冗长,但从安全角度来看,其中似乎没有任何风险。
然而,我在网上找不到任何关于这样做的信息。我正在走一条完全可怕的道路吗?
帮助?
编辑:我想从技术上讲,如果我让 EntityFramework 从数据库生成它们,它们就不是 POCO 类;只是为了消除任何可能的混乱。
I'm a little confused here.
I have my POCO classes created with the entity framework modeled from the datbase.
Obviously, I'd like to use these classes in the client too (and any bookkeeping on them would be nice if I'd like to send them back and re-attach)
I looked through the classes generated for the WCF service reference and it seems a bit verbose to be sending over the internet, but it doesn't look like there's anything risky in there security-wise.
And yet, I can't find anything online about doing this. Am I going down a completely awful path?
Help?
EDIT : I suppose they're technically they're not POCO classes if i had them generated by the EntityFramework from the database; just to clear up any possible confusion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不了解有关系统的更多详细信息的情况下,这是一个很难回答的问题,但最终在 WCF 服务契约中公开 EF 实体是否是正确的路径取决于您正在开发的应用程序的范围和要求。
也许问自己以下问题,这些问题有望指导您的决定:
总之,在有限的情况下,暴露 EF 实体可能是可以接受的,但通常我会设计更改并实现某种模式,将 EF 实体映射到您的 < 处的轻量级“持久性无知”POCO。 href="http://msdn.microsoft.com/en-us/library/ff649690.aspx" rel="nofollow">存储库层。 EF 4.0 确实提供了编写返回 POCO 的上下文的能力,但在我当前的项目中,我们使用 codegen'd 上下文,然后使用 automapper 将 EF 实体映射到我们的数据契约。在存储库层之外,没有任何东西知道 EF 实体,我认为这可以实现更可维护和更健壮的设计。
This is a difficult question to answer without knowing more details about your system, but ultimately whether exposing your EF entities in the WCF service contract is the right path or not is influenced by the scope and requirements of the application you are developing.
Perhaps ask yourself the following questions which will hopefully guide your decision:
In summary there may be a limited number of cases where exposing the EF entities may be acceptable but typically I would design for change and implement some sort of pattern where you map your EF entities to light-weight "persistence-ignorant" POCOs at your repository layer. EF 4.0 does provide the ability to code up a context that returns POCOs, but on my current project we use the codegen'd context and then use automapper to map the EF entities to our data contracts. Outside of the repository layer nothing is aware of the EF entities and I feel this allows for a more maintainable and robust design.