|
Hi,
I am given a hard copy consent form that needs to be in a web page including an area for signature. What's the best way to accomplish this?
Thanks
|
|
|
|
|
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.
|
|
|
|
|
Entity Framework Gotchas – Strategies for Orphaned Child Objects[^]
When you call s.results.remove , you're clearing the parent relationship from the entity, but not marking it for deletion.
When you call context.results.remove , you're marking the entity for deletion.
NB: You can clean up your code and improve the performance by not calling ToList when you only want a single object.
s = context.Students.Where(Function(t1) t1.Value > 5).ToList().First()
s = context.Students.Where(Function(t1) t1.Value > 5).First()
s = context.Students.First(Function(t1) t1.Value > 5)
You should also be aware that First will throw an exception if there are no matching records. You might want to consider using FirstOrDefault instead, which will return Nothing if there are no matching records.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But why when I add a child object I can do directly :
s.results.add(Myobject)
And for the deletion I can't do that as you've said but I should call context.results.remove(Myobject)
So entity framework has different logic for adding and deleting ?
|
|
|
|
|
When you add an entity to the s.results collection, EF sees that it doesn't already exist in the database, and marks it as "Added". It will then insert that record into the database when you save the changes.
When you remove an entity from the s.results collection, EF has no way of knowing whether you wanted to delete the entity from the database, or just remove the connection between the two entities. To avoid inadvertent data-loss, it just tries to remove the connection. To delete it from the database, you have to remove it from the context.results set instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello !
I'm using VB.net 2013 , Entity Framework 6 with sql server 2008R2.
I have a situation where I've made a lot of changes in different entities.
And at the end , I've made a question if the user want to save to database or no .
If yes , I call Savechanges and all the changes are saved.
But if no , I want to undo all the changes made.
Is there any easy way to do this ? I mean , I've found several articles on internet that suggest to undo one by one all the changes.
But is there any easy way , because I don't want to undo specific changes , but all the changes.
Thank you !
|
|
|
|
|
|
Using a simple DAL (not EF) I simply reload the view to get the actual from the database.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you haven't saved the changes, all you have to do is .Dispose() the DbContext instance. The changes die with it.
|
|
|
|
|
I've called
mycontext.dispose.
But after I ca have this code :
Mycontext=New MyEntities
Mycontext.savechanges
and all the changes that I've made before disposing , are saved !!!!!
Why ???
|
|
|
|
|
I have no idea since I can't see your code. You're doing something wrong and actually saving the changes.
Why the hell you're using the last two lines of code after disposing the context is beyond me.
|
|
|
|
|
Just for testing.
So I dispose the context as you've said , and after I try to create a new context , and without making any change , I call Savechanges. And the old changes before disposing are saved.
|
|
|
|
|
The code is doing something other than what you describe. I wrote up a test app to be sure and I don't see the results you're saying you're getting.
The changes I make don't get written to the database and are not persisted in the DbContext change tracker.
Without seeing the code, it's impossible to tell you what's going on.
|
|
|
|
|
Font Stretch and condensed (i.e. Font Scaling) like MSword in vb6 label and textbox
Please Help..
|
|
|
|
|
VB6 was retired many, many years ago; it was replaced with VB.NET.
It is very unlikely you will get a response on how to accomplish your task in VB6; possibly, someone may answer if it is VB.NET related.
Having said that, if you would like some help with an issue, please provide what you've already done. No one will write the code for you, but they may provide help if you show what you've done and explain what it is you're trying to do.
|
|
|
|
|
I want to Fit the Font in Fixed length Textbox and Label how can i do?
|
|
|
|
|
Did you read what I wrote?
Have you provided a code sample?
No one will write the code for you; show what you've done and they may help.
|
|
|
|
|
I have a form which have textbox and dtpicker for inputting data which I store those data in msaccess database. When I export those data to ms excel from another form the date data becomes meaningless or its not exporting as the date enter in the form. Is there anyway to rectify this problem or should I use a text box for inputing date on my form instead of datepicker.
Would be grateful if anyway suggest a way to solve this problem.
Thank you.
Zela
|
|
|
|
|
lazy_dude wrote: the date data becomes meaningless What exactly do you mean?
|
|
|
|
|
I have a vb form where i have number of textbox and dtpicker field, the data input are store in ms access file. When I extract those data from a vb form to ms excel those textbox data comes fine, but the date data which I enter using dtpicker box comes out as numeric not as date enter. I need to transfer those data enter using ms excel file but the date data doesnot come out as I want, thats my problem.
Hope you understand.
|
|
|
|
|
Well, that is basically what you said in your original question, and we still have no idea what you are doing with these values.
|
|
|
|
|
Maybe he's not English Literate.
I'd really like to understand what hep he needs.
Regards, Graham
|
|
|
|
|
So would I, hence my comment.
|
|
|
|
|
We seem to be on the same page, my British friend.
I'm an Australian with Scottish Heritage.
Regards, Graham
|
|
|
|
|
I'm British with mixed heritage, and family connections to Australia.
|
|
|
|