Hi,
I just upgraded to 2009 and I have noticed that when i save an empty string in MSSQL it now stores the value as '' instead of NULL like it used to in 2008 i.e.
CurrentEvent.EventTrigger =
CurrentEvent.Save()
If the SelectedValue was '' it would put NULL in the Table now it puts '' in the table and it is messing my whole application up, and so you know I do this in more than 3,000 places in my code, its a huge application :). So now where i used to do a where on
tblE.Where(tblE.TriggerControl.IsNull)
It does not work becuase there is a '' value in the column instead of NULL.
I hope i explained this decently,
Thanks,Andrew
As far as I know, nothing has changed in this regard since ES 2007. EntitySpaces passes whatever it is told to on to the server. Whether a VARCHAR is set to a value, an empty string, or NULL is up to the developer and the database schema. Here is an excerpt from an NUnit test that is in the ES 2007, 2008, and 2009 SVN branches, and passes in all three. FirstName and LastName allow NULLs and have no DEFAULT set in the schema.
// Set the LastName to null // FirstName to a empty string aggTest.FirstName = String.Empty; aggTest.LastName = null; aggTest.Save(); // Re-read it, confirm null/empty aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(id); Assert.AreEqual("", aggTest.FirstName); Assert.IsNotNull(aggTest.FirstName); Assert.IsNull(aggTest.LastName);
Are you sure nothing else has changed? Maybe you were using StoredProcedure mode in ES 2008 with an SP that prevented empty strings, and are now using ES DynamicSQL mode? Or, maybe a column DEFAULT of '' has been added to the column in the schema?
David Neal Parsonswww.entityspaces.net
It might be a vb thing then, here use the following, as it does like i say, its really odd.
Dim tbl1 As New FormEvents tbl1.AddNew() tbl1.TriggerControl = "" 'inserts '' in the DB tbl1.Save() Dim tbl2 As New FormEvents tbl2.AddNew() tbl2.TriggerControl = Nothing 'inserts a Null in the DB tbl2.Save()Code:18 1 1 1 19 1 1 1 NULL
18 1 1 1 19 1 1 1 NULL
Could it have to do with me moving from asp.net 2.0 to 3.5? or is there something else i'm missing? Before i upgraded to 3.5 and es 2009, the "" always inserted Null into the tables, i'm not sure what else could have changed, nothing in the DB has i'm pretty positive.
Thanks for your help,Andrew
BTW the app may have been writtin in 2007, I can't remember. The main reason this is bugging me is that now I have to and change TONS of code, just so it will insert NULL's in the DB, I have over 200 reports, with about 1,000 stored procedures that rely on the IS NULL or IS NOT NULL, which the '' is not a null, so most all of my reports are broke right now :(.
I do not believe it's a VB/C# thing. The behavior of the code you posted is not odd. It is exactly what is tested for by the NUnit test. If you pass an empty string, it stores ''. If you pass a null, it stores NULL. ES has given the developer this flexibility for years.
Is it possible that this line for ASP.NET 2.0 set the value to null (not an empty string), and that is why it was saved as a NULL to the db?
CurrentEvent.EventTrigger = rcbEventTrigger.SelectedValue
I'm not sure what control that is. Has its behavior changed for ASP.NET 3.5, so that SelectedValue is now an empty string, rather than null?
Ok, thanks for the info,
I'm just going to take your word for it, and change all the code some 5,000 controls that used to work, i'm going to attribute it to upgrade pains, but that is alright my client is paying for it :).
The conrol being used in the example above is a Telerik RadComboBox, but I have the same type of things with TextBox.Text, Dropdown.SelectedValue, all of these used to insert null when the values where ''. It's been over 2 years since i've worked on this project so I might be missing something else, but I upgraded from 2.0 to 3.5, es2007 or 8 to 2009, Telerik from 2007 to 2009. I have a mixture of both Telerik and ASP.net controls, not sure what happen, but like I said i'm just going to charge the client to fix everything :).
Andrew
I'm with Andrew on this one.
I am using 2009.1.209.0, C#, .NET 3.5, SQL Server 2005 and when I insert/update using an empty ASP TextBox, an empty string is inserted into the database. I am pretty sure that previously ES would insert NULL in such cases.
Ref: http://community.entityspaces.net/forums/permalink/2196/2219/ShowThread.aspx#2219
This is what I tried as a test
1 protected void Button1_Click(object sender, EventArgs e)2 {3 SiteConfiguration config = new SiteConfiguration();4 config.LoadByPrimaryKey(1);5 //config.TestString = TextBox1.Text;6 config.TestString = "";7 //config.TestString = null;8 9 config.Save();10 }
Any chance this is bug?
EntitySpaces | Twitter | BLOG | Please honor our Software License
I am using dynamic SQL
Let me know if there's anything I can do to help --- The workaround for this would be painful.
This is nuts but I just downgraded to 2009.1.126.0 and it still doesn't work. I've tried 3.5 and 2.0 version dlls (BTW, what difference does that make?)
The main difference is before I was developing on XP and now I'm on VISTA but I don't see how that would make a difference.
We will be going through our Subversion history and will let you know when this was broken, but we are going to fix it, it's an easy fix and we are very greatful you have found it.
I'd make sure it's really a bug and not something stupid I'm doing before you thank me.
The fact that I can make it happen in one environment and not in another makes me wonder if it's me.