Entity Framework errors while saving base class if there is any inheritance











up vote
0
down vote

favorite












I am using EF 6.1. I have a model "Request" built from the wizard directly from my database. In my context file (EMContext.vb) I have



Public Overridable Property Requests As DbSet(Of Request)


When I type in



        Dim db As New EMContext
Dim req As New Request()
With req
.RequestedBy = "bar"
.EventName = "Goo"
.RequestedOn = Now
.RequestStatusID = 1
End With

db.Requests.Add(req)
db.SaveChanges()


everything works exactly as expected. No problems. It saves.
However, if I add a class (anywhere in the app)



    Class foo
Inherits Request

Public Property s As String
End Class


and then run the exact same code I get




{"An error occurred while updating the entries. See the inner exception for details."}




Looking at the inner exception:




{"Invalid column name 's'.
Invalid column name 'Discriminator'."}




Why in the heck is it even looking at the inherited class properties?
BTW, if I remove all the properties from the inherited class, I still get the Invalid Column 'Discriminator' error.










share|improve this question
























  • Why are you doing this? What is the purpose?
    – OneFineDay
    Mar 12 '15 at 16:50










  • If you want to add more functionality to an Entity class you make a Partial Class.
    – OneFineDay
    Mar 12 '15 at 16:54










  • I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
    – Justin Tolchin
    Mar 12 '15 at 17:43










  • I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
    – Justin Tolchin
    Mar 12 '15 at 17:45












  • Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
    – OneFineDay
    Mar 12 '15 at 17:47















up vote
0
down vote

favorite












I am using EF 6.1. I have a model "Request" built from the wizard directly from my database. In my context file (EMContext.vb) I have



Public Overridable Property Requests As DbSet(Of Request)


When I type in



        Dim db As New EMContext
Dim req As New Request()
With req
.RequestedBy = "bar"
.EventName = "Goo"
.RequestedOn = Now
.RequestStatusID = 1
End With

db.Requests.Add(req)
db.SaveChanges()


everything works exactly as expected. No problems. It saves.
However, if I add a class (anywhere in the app)



    Class foo
Inherits Request

Public Property s As String
End Class


and then run the exact same code I get




{"An error occurred while updating the entries. See the inner exception for details."}




Looking at the inner exception:




{"Invalid column name 's'.
Invalid column name 'Discriminator'."}




Why in the heck is it even looking at the inherited class properties?
BTW, if I remove all the properties from the inherited class, I still get the Invalid Column 'Discriminator' error.










share|improve this question
























  • Why are you doing this? What is the purpose?
    – OneFineDay
    Mar 12 '15 at 16:50










  • If you want to add more functionality to an Entity class you make a Partial Class.
    – OneFineDay
    Mar 12 '15 at 16:54










  • I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
    – Justin Tolchin
    Mar 12 '15 at 17:43










  • I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
    – Justin Tolchin
    Mar 12 '15 at 17:45












  • Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
    – OneFineDay
    Mar 12 '15 at 17:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using EF 6.1. I have a model "Request" built from the wizard directly from my database. In my context file (EMContext.vb) I have



Public Overridable Property Requests As DbSet(Of Request)


When I type in



        Dim db As New EMContext
Dim req As New Request()
With req
.RequestedBy = "bar"
.EventName = "Goo"
.RequestedOn = Now
.RequestStatusID = 1
End With

db.Requests.Add(req)
db.SaveChanges()


everything works exactly as expected. No problems. It saves.
However, if I add a class (anywhere in the app)



    Class foo
Inherits Request

Public Property s As String
End Class


and then run the exact same code I get




{"An error occurred while updating the entries. See the inner exception for details."}




Looking at the inner exception:




{"Invalid column name 's'.
Invalid column name 'Discriminator'."}




Why in the heck is it even looking at the inherited class properties?
BTW, if I remove all the properties from the inherited class, I still get the Invalid Column 'Discriminator' error.










share|improve this question















I am using EF 6.1. I have a model "Request" built from the wizard directly from my database. In my context file (EMContext.vb) I have



Public Overridable Property Requests As DbSet(Of Request)


When I type in



        Dim db As New EMContext
Dim req As New Request()
With req
.RequestedBy = "bar"
.EventName = "Goo"
.RequestedOn = Now
.RequestStatusID = 1
End With

db.Requests.Add(req)
db.SaveChanges()


everything works exactly as expected. No problems. It saves.
However, if I add a class (anywhere in the app)



    Class foo
Inherits Request

Public Property s As String
End Class


and then run the exact same code I get




{"An error occurred while updating the entries. See the inner exception for details."}




Looking at the inner exception:




{"Invalid column name 's'.
Invalid column name 'Discriminator'."}




Why in the heck is it even looking at the inherited class properties?
BTW, if I remove all the properties from the inherited class, I still get the Invalid Column 'Discriminator' error.







vb.net entity-framework inheritance






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 16:18









Cœur

17.3k9102142




17.3k9102142










asked Mar 12 '15 at 16:34









Justin Tolchin

68110




68110












  • Why are you doing this? What is the purpose?
    – OneFineDay
    Mar 12 '15 at 16:50










  • If you want to add more functionality to an Entity class you make a Partial Class.
    – OneFineDay
    Mar 12 '15 at 16:54










  • I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
    – Justin Tolchin
    Mar 12 '15 at 17:43










  • I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
    – Justin Tolchin
    Mar 12 '15 at 17:45












  • Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
    – OneFineDay
    Mar 12 '15 at 17:47


















  • Why are you doing this? What is the purpose?
    – OneFineDay
    Mar 12 '15 at 16:50










  • If you want to add more functionality to an Entity class you make a Partial Class.
    – OneFineDay
    Mar 12 '15 at 16:54










  • I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
    – Justin Tolchin
    Mar 12 '15 at 17:43










  • I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
    – Justin Tolchin
    Mar 12 '15 at 17:45












  • Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
    – OneFineDay
    Mar 12 '15 at 17:47
















Why are you doing this? What is the purpose?
– OneFineDay
Mar 12 '15 at 16:50




Why are you doing this? What is the purpose?
– OneFineDay
Mar 12 '15 at 16:50












If you want to add more functionality to an Entity class you make a Partial Class.
– OneFineDay
Mar 12 '15 at 16:54




If you want to add more functionality to an Entity class you make a Partial Class.
– OneFineDay
Mar 12 '15 at 16:54












I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
– Justin Tolchin
Mar 12 '15 at 17:43




I am doing this to pass data from a JSON call that includes more than just the request. On the server side, I am breaking out the original Request class data from the inherited data and doing multiple operations with it. However, the thing I don't get is why adding a class that inherits from the base anywhere in the code breaks the parent class. How can creating a separate class have any impact on the base class when the inherited class isn't even referenced?
– Justin Tolchin
Mar 12 '15 at 17:43












I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
– Justin Tolchin
Mar 12 '15 at 17:45






I don't want to add functionality to the base class. I suppose I could create another class that declares the request class in it, then add the other 2 properties, but that doesn't change the fact that this behavior seem completely wrong.
– Justin Tolchin
Mar 12 '15 at 17:45














Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
– OneFineDay
Mar 12 '15 at 17:47




Then create a custom class that the json parses to and then you can call the Entity and make it from this class.
– OneFineDay
Mar 12 '15 at 17:47












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Then create a custom class that the json parses to and then you can call the Entity and make it from this class.



<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class


Usage:



Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...





share|improve this answer





















  • This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
    – Justin Tolchin
    Mar 13 '15 at 21:54










  • It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
    – OneFineDay
    Mar 13 '15 at 22:01










  • I appreciate your suggestions. Thank you.
    – Justin Tolchin
    Mar 14 '15 at 1:15










  • It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
    – Justin Tolchin
    May 21 '15 at 18:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29015342%2fentity-framework-errors-while-saving-base-class-if-there-is-any-inheritance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Then create a custom class that the json parses to and then you can call the Entity and make it from this class.



<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class


Usage:



Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...





share|improve this answer





















  • This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
    – Justin Tolchin
    Mar 13 '15 at 21:54










  • It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
    – OneFineDay
    Mar 13 '15 at 22:01










  • I appreciate your suggestions. Thank you.
    – Justin Tolchin
    Mar 14 '15 at 1:15










  • It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
    – Justin Tolchin
    May 21 '15 at 18:01















up vote
0
down vote



accepted










Then create a custom class that the json parses to and then you can call the Entity and make it from this class.



<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class


Usage:



Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...





share|improve this answer





















  • This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
    – Justin Tolchin
    Mar 13 '15 at 21:54










  • It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
    – OneFineDay
    Mar 13 '15 at 22:01










  • I appreciate your suggestions. Thank you.
    – Justin Tolchin
    Mar 14 '15 at 1:15










  • It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
    – Justin Tolchin
    May 21 '15 at 18:01













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Then create a custom class that the json parses to and then you can call the Entity and make it from this class.



<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class


Usage:



Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...





share|improve this answer












Then create a custom class that the json parses to and then you can call the Entity and make it from this class.



<Serializable()>
Public Class jSonParsedObject
'properties that match the Entity object
'custom properties you need for other work
End Class


Usage:



Dim jsonObj As jSonParsedObject = SomeMethodThatParsesAndReturnsData()
Dim req As New Request()
With req
.RequestedBy = jsonObj.RequestedBy
.EventName = jsonObj.EventName
.RequestedOn = jsonObj.RequestedOn
.RequestStatusID = jsonObj.RequestStatusID
End With
...






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 12 '15 at 17:51









OneFineDay

8,33831733




8,33831733












  • This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
    – Justin Tolchin
    Mar 13 '15 at 21:54










  • It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
    – OneFineDay
    Mar 13 '15 at 22:01










  • I appreciate your suggestions. Thank you.
    – Justin Tolchin
    Mar 14 '15 at 1:15










  • It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
    – Justin Tolchin
    May 21 '15 at 18:01


















  • This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
    – Justin Tolchin
    Mar 13 '15 at 21:54










  • It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
    – OneFineDay
    Mar 13 '15 at 22:01










  • I appreciate your suggestions. Thank you.
    – Justin Tolchin
    Mar 14 '15 at 1:15










  • It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
    – Justin Tolchin
    May 21 '15 at 18:01
















This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
– Justin Tolchin
Mar 13 '15 at 21:54




This may work, but it means creating a custom object/class which is what I didn't want to do. The main question still remains though. Why does creating an inherited class break EF?
– Justin Tolchin
Mar 13 '15 at 21:54












It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
– OneFineDay
Mar 13 '15 at 22:01




It's no more than creating an inherited class. I don't know the answer to your question and so far no one else chimed in.
– OneFineDay
Mar 13 '15 at 22:01












I appreciate your suggestions. Thank you.
– Justin Tolchin
Mar 14 '15 at 1:15




I appreciate your suggestions. Thank you.
– Justin Tolchin
Mar 14 '15 at 1:15












It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
– Justin Tolchin
May 21 '15 at 18:01




It appears this just isn't possible in EF. This was the best suggestion in that I ended up needing to build a separate class which found out is referred to as a DTO ( Data Transfer Object).
– Justin Tolchin
May 21 '15 at 18:01


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29015342%2fentity-framework-errors-while-saving-base-class-if-there-is-any-inheritance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy