last day (15 days later) » 

6:47 PM
0
A: Database not updated bug - Entity Framework

ShawnI will make this an answer because I am pretty sure if you are hitting the action method at some point you will need to do this before saving changes. connection.Entry(record).State = EntityState.Modified; connection.SaveChanges(); This allows EF to issue an update on the record passed. I...

 
I still lean towards the bit not mapping correctly. EF in my experience has always treated bit fields as boolean in code.
 
I tried this and it still showed no change in the database :/
 
See my latest update bool might need to be a nullable?
 
Yes, and I've tried it both ways
 
Ok let's take a step back and cover some basics: 1) You hit the DisableRow method correct (in debug)? 2) I assume the connection is working (record != null)? 3) Is the database table correctly created by code first (with bit field etc)
 
6:47 PM
Also, I did need to cast to EntityState here: connection.Entry(record).State = (EntityState) System.Data.EntityState.Modified;
 
Ok you shouldnt need to do a cast like that
 
Thanks for helping out.
 
EntityState is just an enum if you include the using statement for System.Data you should be able to just use EntityState.Modified
np
using is system.data.entity not system.data btw
 
I get the error: Cannot convert source type: 'system.data.entitystate' to target type 'system.data.entity.entitystate'
 
what version of ef are you using?
 
6:51 PM
let me check quick
6.1.3
 
ok let me double check something
Ok so first thing is first did you verify on your table it is getting created with a bit field
 
Yes, I have a state column of data type bit
Each bit value is set to true
 
ok one thing you could try just for testing sake is to re-create the record you are trying to update it
instead of "finding" it
 
Okay
 
that would allow you to use the EntityState code I sent earlier in theory...im confused why you would have to cast though you need to maybe check your using statement and see if the dll System.Data is in your references
might even be worth uninstallng/reinstalling your EF nuget package (sorry just spit balling here)
 
7:01 PM
I just deleted the state table column and am trying to recreate it. The table column was actually created in SQL management studio, not VS
Creating it in VS now
 
OH
 
Idk if that would make a difference
 
that could cause issues ive never seen trying to use code first in VS and changing the DB manually worked well
which approach are you trying to follow database first or code first (code first generates the DB from your POCO classes, so Category in this case would map to a table in the db but you don't create it with SQL)
 
database first
 
ok here is the deal you should use the EF tools to generate your classes then
 
7:05 PM
Because im basically adding another column to a table that was created previously
 
without EF you mean?
You might need to install EF power tools to generate the model (either edmx or classes)...I can't remember if that tooling comes by default in VS...let me know what VS version you are using
 
VS 2012, is it a bad idea to create the column manually. Maybe i could update the db from the model
 
The table wasnt created with entity framework just SQL right?
 
Yeah
 
if that is the case manually adding the column and reverse engineering your db with EF in visual studio is the approach you want
 
7:08 PM
Okay
 
so when you have the table how you want it go to VS and add an item to your project
under items should be a section that says data
Choose ADO.NET Entity Data Model
one sec thats not the approach I wanted to tell you about let me look in one of my solutions
 
Okay
 
OKay yeah what i said is correct tell me when that comes up what options you have
thatll determine if you need the power tools i think
or hell you can just install em useful anyway
 
I already have a CategoryDB.edmx, is creating a new one just going to build the ties to the new column?
 
itll build a fresh copy didnt know you had one...you could in theory open the edmx right click in the designer and update from database
 
7:17 PM
Ill try that
one sec
Now it actually broke my build because I do not have state set to NOT NULL, which is good news because now it is recognizing that the column is there
 
good on the right track id say
 
I'm trying to change it to NOT NULL, but I'm getting the error: Cannot insert the value NULL into column 'state', table 'QualityDB.dbo.Tmp_ReworkCategory'; column does not allow nulls. INSERT fails.
That's just when I try to make it not null. I'm not filling it yet
 
Maybe set a default on the column when you add it?
false or 0
 
Its saying error when trying to evaluate default, going to delete the column and try again. Lots of weird behavior
 
Yeah without seeing it a little hard to troubleshoot
 
7:31 PM
Yeah, at least its recognizing the column. I can figure out this small stuff. Thanks so much for your help
 
no problem best of luck
 

last day (15 days later) »