简体   繁体   English

NHibernate,WCF,WPF体系结构问题

[英]NHibernate, WCF, WPF architectural issues

I want to display a bunch of different data objects that I have using WPF. 我想显示一堆使用WPF的不同数据对象。 These data objects vary in data. 这些数据对象的数据不同。 They have common properties, but they also have some differing properties. 它们具有共同的属性,但也具有一些不同的属性。 There will be a "master" class that references these entities. 将有一个引用这些实体的“主”类。 Each master class can have one of each of these data types. 每个主类可以具有以下每种数据类型之一。

I'm finding it difficult to design them even on a database level. 我发现即使在数据库级别也很难设计它们。 Should I have one table per data object, thereby making it easy to get the data using NHibernate (just reference one of these entities). 我是否应该为每个数据对象创建一个表,从而使使用NHibernate轻松获取数据(只需引用这些实体之一)即可。 This makes it quite difficult to consume using WCF though. 但是,这使得使用WCF进行消费非常困难。 If I'm wanting to display this data in WPF, I'll probably need a collection of some variety, and that's what I don't have. 如果我想在WPF中显示此数据,则可能需要各种集合,而这正是我所没有的。

I could put all data types into the same table and have a multi-column unique constraint on the owner id and data type id. 我可以将所有数据类型放入同一张表中,并对所有者ID和数据类型ID进行多列唯一约束。 But then I may have null properties in my entities, and it would also be hard to display in the UI. 但是这样我的实体中可能会有null属性,并且也很难在UI中显示。 It would also complicate editing the entities, as I'd have to mindful of which properties the user can and can't edit. 这也将使实体的编辑变得复杂,因为我必须牢记用户可以编辑和不能编辑哪些属性。

I guess visually, the entities would look like this in the first way: 我想从视觉上看,实体在第一种方式下看起来像这样:

 public class Master
{
    int Id
    DataType1 Data1
    DataType2 Data2
}

public class DataType1
{
    int Id
    string SomeString
    string AnotherString
}

public class DataType2
{
    int Id
    string SomeString
    string DifferentString
}

And this in the second way: 这是第二种方式:

public class Master
    {
        int Id
        List<DataType> Types
    }

public class DataType
{
   int Id
   string SomeString
   string AnotherString
   string DifferentString
}

So which would be the best way? 那么哪种方法是最好的呢? Or is there a different way that's better than both (there probably is)? 还是有另一种方法比两者都更好(可能有)?

It is really depend on your business case as it is not such an architectural issue. 实际上,这不是架构问题,这完全取决于您的业务案例。 If you have known number of DataType-s do static (one to one) reference (first example). 如果您知道DataType的数量,请执行静态(一对一)引用(第一个示例)。

If you have unknown or dynamic number of the DataType-s you have no other option than to make these DataType-s as a list in your "Master" object. 如果您有未知或动态的DataType-s数,则除了将这些DataType-s列为“ Master”对象中的列表之外,别无选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM