Dailycode.info

Short solution for short problems

EF : Oracle and EF Code First “Invalid column name 'Discriminator'”

I got this little nasty error when working with EF6 and Oracle DB: ORA-00904: "Extent1"."Discriminator"

Didn't look that far, based on this post I found my answer!

I had a class: Clients, added to the context. 

That worked fine. 

Now I created a second class, ClientExtra not added to the context but this inherited from the Client object.

(Why you might ask, I used this class in a database query, it had some extra properties and no table reflecting in the already exiting DB)

After doing this, EF gave me the above error.

It could look like this:

public class Client
{
    public int Id { get; set; }

    public string Name { get; set; }
}

public class ClientExtra : Client
{
    public string City { get; set; }
}

Solution

First create a common base class, ClientBase, add all properties from the client object. Do not add the ClientBase to the context. Then you have Client en ClientExtra inherit from this base class without problems.

public class BaseClient
{
    public int Id { get; set; }

    public string Name { get; set; }
}

//In the context
public class Client : BaseClient
{ }

//Not in the context
public class ClientExtra : BaseClient
{
    public string City { get; set; }
}




blog comments powered by Disqus