班实体;像类的继承问题 [英] Classes to Entities; Like-class inheritence problems

查看:100
本文介绍了班实体;像类的继承问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了工作,我和几个朋友正在试图建立各种各样的游戏;我们构建了一些它的方式工作得很好,对于普通的面向对象的方法,但由于大多数开发商将证明这并不总是本身很好的转化到数据库持久的方式。

Beyond work, some friends and I are trying to build a game of sorts; The way we structure some of it works pretty well for a normal object oriented approach, but as most developers will attest this does not always translate itself well into a database persistent approach.

这是不是我们有什么绝对的布局,它只是一个代表性的缘故给出的样本模型。

This is not the absolute layout of what we have, it is just a sample model given for sake of representation.

整个项目正在做在C#4.0中,我们必须使用实体框架4.0的每一个意图(除非功能NHibernate真的可以为我们提供一些我们完全无法EF做)。

The whole project is being done in C# 4.0, and we have every intention of using Entity Framework 4.0 (unless Fluent nHibernate can really offer us something we outright cannot do in EF).

一,我们继续运行横跨在继承中数据库模型的东西的问题。使用实体框架设计师,我的可以得出同样的代码,下面我有;但我敢肯定,这是很明显的,像它预计它不工作。

One of the problems we keep running across is inheriting things in database models. Using the Entity Framework designer, I can draw the same code I have below; but I'm sure it is pretty obvious that it doesn't work like it is expected to.

要澄清一点; 项有奖金,它可以是任何东西。因此,游戏的每一部分必须从类似的派生因此,无论是什么'改变'这是所有处于基本够用的水平被勾搭成。听起来相当简单明了,对吧?

To clarify a little bit; 'Items' have bonuses, which can be of anything. Therefore, every part of the game must derive from something similar so that no matter what is 'changed' it is all at a basic enough level to be hooked into. Sounds fairly simple and straightforward, right?

那么,我们继承,涉及到从单位游戏中的一切。重量,尺寸,随机(认为像骰子,也许?),而且会有其他类似的实体。其中有些相似,但在代码中,他们将各自不同的反应。

So then, we inherit everything that pertains to the game from 'Unit'. Weights, Measures, Random (think like dice, maybe?), and there will be other such entities. Some of them are similar, but in code they will each react differently.

我们遇到与抽象这种事情到数据库模型一个真正的大问题。如果没有枚举的支持,它被证明是难以转化为多个表仍然有着共同的上市。我们描述一个解决方法是使用一个关键一环式的做法,在那里,重视人物都存储在一个环与钥匙,其中每个按键都有一个代表类型的值。此功能的作品,但我们已经发现它变得非常缓慢,表现不佳。因为开始感到仿佛一切都'倾倒'为一类,我们也不喜欢这种方式;这使得管理和逻辑结构难以坚持。

We're having a really big problem with abstracting this kind of thing into a database model. Without 'Enum' support, it is proving difficult to translate into multiple tables that still share a common listing. One solution we've depicted is to use a 'key ring' type approach, where everything that attaches to a character is stored on a 'Ring' with a 'Key', where each Key has a Value that represents a type. This works functionally but we've discovered it becomes very sluggish and performs poorly. We also dislike this approach because it begins to feel as if everything is 'dumped' into one class; which makes management and logical structure difficult to adhere to.

我希望别人可能有什么我可以解决这个问题做了一些想法。它真正推动我逼疯了;为摘要;我们的目标是建立一个类型(单位),可以用来作为通用的参考跨越相对全球范围内基本类型(每个类型表),而不必事事转储到一个单一的集合。我可以用一个接口来确定实际的行为的所以这不是太大的问题。

I was hoping someone else might have some ideas on what I could do with this problem. It's really driving me up the wall; To summarize; the goal is to build a type (Unit) that can be used as a base type (Table per Type) for generic reference across a relatively global scope, without having to dump everything into a single collection. I can use an Interface to determine actual behavior so that isn't too big of an issue.

这是大致相同的实体框架中表达想法。

This is 'roughly' the same idea expressed in the Entity Framework.

推荐答案

你试过每个具体类型映射表为单位?即使用ID字段措施,重量和随机链接表? (每个人都有一个ID列,它们都是通过这个关系。)

Have you tried a Table per Concrete Type mapping for Unit? i.e. using the Id field to link the Measure, Weights and Random tables? (each has an Id column and they are related through this.)

我想告诉你表和措施之间的关系将是每类映射表问题。表无法映射如果单位措施的类型,类型由单位鉴别列决定只的措施。随着TPCT可以成功地映射表采取措施,因为它可以使用标识为'回到'的单位表。

I think the relationship you show between Sheet and Measure is going to be problematic in a Table per class mapping. Sheet can't map to just Measures if the type type of unit 'measure' is determined by a discriminator column in Units. With TPCT you can map Sheet to Measures successfully because it can use the Id to 'get back' to the Units table.

不幸的通过对TPCT示例的方式是非常小:有时它似乎采取的几次迭代{编辑模型,导出数据库,使SSMS的变化,导入数据库} ...得到它的权利。

Unfortunately there's very little by way of examples for TPCT: sometimes it seems to take a few iterations of {edit model, export database, make changes in SSMS, import database} ... to get it right.

这篇关于班实体;像类的继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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