Entity Framework - Ria Service code generation
I have a table with the following:
CREATE TABLE [Location]([ADDRESS1] [nvarchar](50) NOT NULL DEFAULT (' '));
I import it into Entity Framework 4.1.
Entity Framework’s designer shows this:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttri开发者_运维知识库bute()]
public global::System.String ADDRESS1
{
get
{
return _ADDRESS1;
}
set
{
OnADDRESS1Changing(value);
ReportPropertyChanging("ADDRESS1");
_ADDRESS1 = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("ADDRESS1");
OnADDRESS1Changed();
}
}
private global::System.String _ADDRESS1 = " ";
partial void OnADDRESS1Changing(global::System.String value);
partial void OnADDRESS1Changed();
When I build it, I get a *.web.g.cs file in my Silverlight application and the field looks like this:
[DataMember()]
[Required()]
[StringLength(50)]
public string ADDRESS1
{
get
{
return this._address1;
}
set
{
if ((this._address1 != value))
{
this.OnADDRESS1Changing(value);
this.RaiseDataMemberChanging("ADDRESS1");
this.ValidateProperty("ADDRESS1", value);
this._address1 = value;
this.RaiseDataMemberChanged("ADDRESS1");
this.OnADDRESS1Changed();
}
}
}
Am I missing a setting in Entity Framework? It appears to me that if the field is NOT NULL code generation is flagging the field as required, even though I am telling it the default is string.empty (or blank).
NOT NULL means required. That's the only thing that controls where a value must be supplied.
An empty string for new records does not mean you can't explicitly insert a NULL value, but NOT NULL will stop you doing that.
精彩评论