Entity Framework trying to save empty string as null in database
I'm having to work with a database table, that for whatever reason, requires all entries to have a value(NOT NULL). Not all entries are relevant to the user and they will be leaving entries blank when entering them through a webform. I'm using a FormView databound using Entity Framework.
The problem I'm running into is, that instead of entering an empty or blank string for TextBoxes with no text, it is trying to use a NULL value. Is there a way to just enter a blank string to appease the database constraints?
I wish I could just change these in the database to allow nulls, but unfortunately I don't have access.
Here's a snippet from the aspx:
<asp:TextBox ID="CustIdTextBox" runat="server" Text='<%# Bind("CustId") %>' />
It looks like entity framework is taking the empty string and deciding to save it to the database as NULL.
Well we definietly need some code, but I'm guessing the textbox.text property is not initialized, so it's going to give you NULL. Just initialize it to an empty string, or replace the null with string.empty before you update the DB.