3

I'm trying to wrap my head around the Entity Framework and am having trouble understanding how one would code to an interface (or, perhaps, whether coding to the interface is possible). I'm fairly confident in C#, but mostly due to my ability to program in so many other languages, so forgive any ignorances.

Given:

public interface IInputSource
{
    float GetCurrentValue(DateTime timestamp);
}

public class PatternSource : IInputSource
{
    …
    float GetCurrentValue(DateTime timestamp)
    {
        // generate value based on probability equation
    }
    …
}

public class TimeSeriesSource : IInputSource
{
     …
     float GetCurrentValue(DateTime timestamp)
     {
         // look up value in a key/value store
     }
     …
 }

I want to code a node class to the interface, since there are 5 or 6 distinctly different source types:

public class Node
{
    …
    public IInputSource Inflow { get; set;}
    …
 }

It seems that the O/M from Entity Framework would never be able to resolve the concrete class that Node would be referencing, and as such, one would simply not be able to code to an interface. Is this indeed the case?

If not, can someone give me an example of how this would be accomplished in EF 4? I'm using VS2010 & .NET 4 and I'm coming from a code-first mentality).

1
  • One possible option to this, of course, is to create a base class for InputObject and subclass all from that, but I wanted to favor composition over inheritance. I just wonder if this is not possible in this situation. Commented Sep 7, 2010 at 19:09

1 Answer 1

1

I've never seen any ORM framework that can handle this. Your best bet is an abstract base class that serves as a stub for the ORM.

If you have common functionality that your concrete classes inherit, the abstract base class can inherit from the desired superclass, or you could use decorators to compose the desired functionality.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.