views:

23

answers:

1

I'll try to explain the problem I'm currently facing as simply as possible. The project I'm currently working on is required to analyze some financial data. For convenience, this data should be stored in a database, so I'm tasked with creating a database model. While the database wasn't required up until now, the application itself has been developed for a number of years and already has all the data types and classes defined, so my task is to match the database model to the classes used by application. Here's a simplified breakdown of a class composition used by application to work with the data.
To start with, there's an abstract Entry class that all other financial data entries are inherited from:

abstract class Entry
{
    public Guid ID { get; set; }
    public string Name { get; set; }
}

Different financial data comes in different formats an is relevant to different points in time. To reflect this, there's a number of interfaces that are implemented by concrete data types. As an example, lets say that all the data can either be relative to a certain point in time or a period in time. Take currency rate for example. It only changes once a day. GDP, on the other hand, is usually provided for a certain period (either quarterly or yearly). This is reflected by the classes provided below.

class SingleDateEntry : Entry
{
    public DateTime Date { get; set; }
}

class PeriodEntry : Entry
{
    public DateTime PeriodStart { get; set; }
    public DateTime PeriodEnd { get; set; }
}

Furthermore, the data can be represented in different formats. Some data only has a single value, like the currency rate for example, other data can come in data sets, like daily stock prices, which have an opening and closing daily prices, as well as maximum and minimum daily prices.

interface ISingleValueEntry
{
    public double Value { get; set; }
}

interface IMinMaxEntry
{
    public double MinPrice { get; set; }
    public double MaxPrice { get; set; }
}

interface IOpenCloseEntry
{
    public double OpenPrice{get;set;}
    public double ClosePrice{get;set;}
}

As an example, the daily currency rate, since it is associated with a single day in the past and only has one value, could be represented by a class that looks like this:

class DailyCurrencyRate : SingleDateEntry, ISingleValueEntry
{
}

The stock prices have a number of different values associated with them, so they can be represented like this:

class DailyStockPrice : SingleDateEntry, IOpenCloseEntry, IMinMaxEntry
{
}

And finally, GDP, since it is associated with a period in time and has a single value, would look like this:

class GDP : PeriodEntry, ISingleValueEntry
{
}

Unfortunately, I haven't worked with EF before, and when I tried to implement this simplified scenario of the actual problem I've run into a number of problems, so I would appreciate any suggestions that could help me out resolving them.
To start with, how to deal with multiple interface implementations? As far as I know EF doesn't support multiple inheritance, and by using associations, I don't get classes that implement them, rather it generates classes that contain references to objects that implement these interfaces, which is bad, since it doesn't matches the interface expected by the application. Furthermore, what type of inheritance should be used it this scenario? From what I understood after my research, TPC would be a better strategy, but I might be wrong about that.
Thanks in advance for any pointers, suggestions and "gotchas".

+1  A: 

Multiple inheritance is not provided by .NET framework and you don't use multiple inheritance. Each your class inherits only from single parent class. I just tested simple scenario with Code first approach (not part of EF4.0). I modeled three classes in A, B inherited from A and C inherited from B. I stored C as TPH (TPH for code first) without any problems. It will also work with common EF approach.

Ladislav Mrnka
Right, so I went with the Code first approach. Seemed easier in the given situation.
L.E.O
Actual problem with Code first is that it is only in CTP version.
Ladislav Mrnka