Code First Class:
public class Product
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductId{ get; set; }
[MaxLength(256), Required]
public string ProductName { get; set; }
public DateTime CreatedTime { get; set; }
}
In the database, i give the CreatedTime Column the DEFAULT value "(getdate())", so that the database will generate a value for us on insert operation.
My Question: Is there some kind of DataAnnotations/something else that can do the following things:
- can tell Entity Framework(Code First Mode) to include CreateTime when Building up the Database;
- can tell EF NOT to include CreateTime when Inserting a new column into the Database;
- can tell EF to retrieve back all the columns including CreateTime when Selecting from the database.
So that, I can treat the CreatedTime Column in the Client Side the same as the ProductId Column(which is the Identity Column: value Only can be generated by the Database; will NOT be included when Inserting a new column; will be included when Selecting...).
I think it's much more clear now, sorry for the misunderstanding!
Dean