I've had a look at the Entity Framework 4. While generating code for the SQL Server 2008 I came to the point where I want to define some default values for some fields.
how to define in the designer for a Created DateTime Field the DateTime.Now default value?
-> Error 54: Default value (DateTime.Now) is not valid for DateTime. The value must be in the form 'yyyy-MM-dd HH:mm:ss.fffZ'
how to make for code generation a string Field unique. Like E-Mail开发者_Python百科 or Username can exists only once in the table.
I've search alot in the internet and also checked my books Pro Entity Framework 4.0 and Programming Entity Framework. But none of them seems to come up with the default value issue, or using sql commands as default values for database generation.
Another thing is, how to prevent on database generation always from droping tables? Instead i want to append non existing fields and keep the data.
Thanks for any suggestions.
You can always define partial class and initialize value in costructor:
public partial class MyEntityClass
{
public MyEntityClass()
{
CreationDate = DateTime.Now;
}
}
If field is unique, you'll have to check it yourself and include in your validation logic.
精彩评论