CTP5 - 自创建数据库以来“上下文已发生变化”的帮助 [英] CTP5 - help with "context has changed since the database was created"

查看:65
本文介绍了CTP5 - 自创建数据库以来“上下文已发生变化”的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的"上下文已经改变了正确的数据库被创建" - 我看到一些CTP4的帖子表明要使用Database.SetInitializer。我没有看到CTP5的这个命名空间/ API?移动了吗?

I'm getting the "context has changed sine the database was created" -- and I saw some posts for CTP4 indicate to use the Database.SetInitializer. I don't see this namespace/API for CTP5? Has it moved?

我可能在我们的解决方案中做了一些奇怪的事情:

I'm potentially doing something a bit odd in our solution too:

我有两个项目/名称空间:例如AcmeCompany.Common和AcmeCompany.AppXyz

I have two projects/namespaces: e.g. AcmeCompany.Common and AcmeCompany.AppXyz

AcmeCompany.Common名称空间内是我们公司使用的常见对象的域模型,例如用户,角色,权限,地址,电话,国家等 - 即appliation不可知项。

Inside the AcmeCompany.Common namespace are domain models for common objects used in our company, such as User, Role, Privilege, Address, Phone, Country, etc -- i.e. appliation agnostic items.

AcmeCompany.AppXyz名称空间内是特定项目/区域的域模型。

Inside the AcmeCompany.AppXyz namespace are the domain models for a specific project/area.

因此,我有两个DbContexts。 AppXyzContext包含来自两个命名空间的所有域模型,并且我使用此上下文创建数据库。

Consequently, I have two DbContexts. The AppXyzContext includes all the domain models from both namespaces, and it is with this context that I create the database.

但是,如果我尝试使用CommonContext访问数据库,我会得到"上下文已经改变了正确的数据库被创建"。

However, if I try to use the CommonContext to access the database, I get the "context has changed sine the database was created".

我做了一些可怕的错误吗?您是否看到了我应该采用的更好的设计模式?

Am I doing something horribly wrong? Do you see a better design pattern I shouldbe employing instead?

----更新:----

---- UPDATE: ----

似乎我能够有多个不同的DbContext ...所以我面临的错误可能只是因为我不小心改变了其中一个类。但是,我仍然感谢有关生成一个
数据库的最佳实践的评论,该数据库在不同的应用程序中具有公共实体/表。

It seems that I am able to have multiple, different DbContext... so the error I was facing was likely just due to me accidentally changing one of the classes. However, I would still appreciate any comments on best practices, with regards to generating a database that has common entities/tables across different applications.

示例:

我有asp.net Forms Authentication代码以及User的域模型/业务对象。在该项目命名空间中,我放置了UserRepository以及自定义MembershipProvider。在不同的命名空间中,我的域模型可能具有审计
字段,例如"CreatedBy,ModifiedBy"。有没有人想过这种方法的缺陷?

I have asp.net Forms Authentication code along with my domain models / business objects of User. In that project namespace, I have placed the UserRepository as well as the custom MembershipProvider. In a different namespace, my domain models may have audit fields, such as "CreatedBy, ModifiedBy". Anyone have thoughts on the pitfalls of this approach?

谢谢

Ray

推荐答案

您是否看到了我应该采用的更好的设计模式?

这正是我尝试实现的方案 - 有基础公共项目中的域模型,基本约定和基本上下文,并在站点特定项目中使用许多继承策略。我的用例是用于内容管理,使用常见的
页面,人员,地点,产品模型,可以在各个Web项目中进行自定义。但是使用继承的许多组合 - 从基础上下文继承,使用基本模型,使用自定义约定 - 在CTP5中看起来很麻烦,例如。

我的查询在这里
 我相信正在为RTM版本解决问题,因为很难发现哪个元素导致了映射问题。所以我非常期待RTM!

This is exactly the scenario I am trying the achieve - have base domain models, base conventions and base contexts in a common project and use a number of inheritance strategies in site specific projects. My use case is for content management, with common Page, Person, Place, Product models, which can be customised in individual web projects. But a number of combinations using inheritance - inherit from base context, using base models, with custom conventions - in CTP5 seem troublesome eg. my query here which I believe are being ironed out for the RTM version, as it was hard to discover which element caused the mapping issue. So I'm very much looking forward to the RTM!

 

 

  ;




这篇关于CTP5 - 自创建数据库以来“上下文已发生变化”的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆