Click here to Skip to main content
15,944,136 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Dave Kreskowiak15-Feb-18 17:45
mveDave Kreskowiak15-Feb-18 17:45 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Richard Deeming16-Feb-18 1:44
mveRichard Deeming16-Feb-18 1:44 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Dave Kreskowiak16-Feb-18 5:09
mveDave Kreskowiak16-Feb-18 5:09 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Richard Deeming16-Feb-18 5:28
mveRichard Deeming16-Feb-18 5:28 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Dave Kreskowiak16-Feb-18 6:58
mveDave Kreskowiak16-Feb-18 6:58 
GeneralRe: Visual studio 2017 : How can i use Entity framework 6 with Database first ? Pin
Mycroft Holmes17-Feb-18 22:43
professionalMycroft Holmes17-Feb-18 22:43 
QuestionReplicate a form Pin
sunsher15-Feb-18 0:13
sunsher15-Feb-18 0:13 
QuestionEntity framework : Error when deleting from child entities Pin
desanti14-Feb-18 7:22
desanti14-Feb-18 7:22 
Hello !
I'm using vb.net 2013 , Entity framework 6 and SQL server 2008R2.
I'm trying to delete from child entities , and this does not work. But if I try to delete directly from context , this works.
In my database I have 2 tables Students and Result

This is my code that does not work :
Dim context as Myentities=New myentities.
Dim s as student.
Dim lresult as new list (of result)
s=context.students.where(Function(t1) t1.value>5).Tolist.first
lresult=(from t in s.results where t.vl2=7 select t).Tolist

for each rs as result in lresult
if rs.vl3=11 then s.results.remove(rs)
Next
Context.savechanges

This code produce an error on the last line( context.savechanges ) :

An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll
Additional information: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.


But if I change the line that delete the item , like below , this works :

Dim context as Myentities=New myentities.
Dim s as student.
Dim lresult as new list (of result)
s=context.students.where(Function(t1) t1.value>5).Tolist.first
lresult=(from t in s.results where t.vl2=7 select t).Tolist

for each rs as result in lresult
if rs.vl3=11 then context.results.remove(rs)
Next
Context.savechanges


Why my first code does not work ?
Thank you !

modified 14-Feb-18 14:33pm.

AnswerRe: Entity framework : Error when deleting from child entities Pin
Richard Deeming14-Feb-18 8:51
mveRichard Deeming14-Feb-18 8:51 
GeneralRe: Entity framework : Error when deleting from child entities Pin
desanti14-Feb-18 9:43
desanti14-Feb-18 9:43 
GeneralRe: Entity framework : Error when deleting from child entities Pin
Richard Deeming14-Feb-18 9:51
mveRichard Deeming14-Feb-18 9:51 
QuestionHow can i undo all changes made to entities Pin
desanti13-Feb-18 8:45
desanti13-Feb-18 8:45 
AnswerRe: How can i undo all changes made to entities Pin
Maciej Los13-Feb-18 9:21
mveMaciej Los13-Feb-18 9:21 
AnswerRe: How can i undo all changes made to entities Pin
Mycroft Holmes13-Feb-18 13:26
professionalMycroft Holmes13-Feb-18 13:26 
AnswerRe: How can i undo all changes made to entities Pin
Dave Kreskowiak13-Feb-18 15:12
mveDave Kreskowiak13-Feb-18 15:12 
GeneralRe: How can i undo all changes made to entities Pin
desanti14-Feb-18 2:16
desanti14-Feb-18 2:16 
GeneralRe: How can i undo all changes made to entities Pin
Dave Kreskowiak14-Feb-18 2:22
mveDave Kreskowiak14-Feb-18 2:22 
GeneralRe: How can i undo all changes made to entities Pin
desanti14-Feb-18 2:41
desanti14-Feb-18 2:41 
GeneralRe: How can i undo all changes made to entities Pin
Dave Kreskowiak14-Feb-18 6:47
mveDave Kreskowiak14-Feb-18 6:47 
QuestionFont Stretch and condensed (i.e. Font Scaling) like MSword in vb6 label and textbox Pin
SNB172613-Feb-18 3:00
SNB172613-Feb-18 3:00 
AnswerRe: Font Stretch and condensed (i.e. Font Scaling) like MSword in vb6 label and textbox Pin
Tim Carmichael13-Feb-18 3:05
Tim Carmichael13-Feb-18 3:05 
GeneralRe: Font Stretch and condensed (i.e. Font Scaling) like MSword in vb6 label and textbox Pin
SNB172613-Feb-18 4:18
SNB172613-Feb-18 4:18 
GeneralRe: Font Stretch and condensed (i.e. Font Scaling) like MSword in vb6 label and textbox Pin
Tim Carmichael13-Feb-18 4:39
Tim Carmichael13-Feb-18 4:39 
Questiondtpicker field problem Pin
lazy_dude10-Feb-18 4:36
lazy_dude10-Feb-18 4:36 
AnswerRe: dtpicker field problem Pin
Richard MacCutchan10-Feb-18 5:33
mveRichard MacCutchan10-Feb-18 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.