MaDOS, mySql . EF , .
EF, db.
db-
public class MySqlDbContext : DbContext
{
public DbSet<MyOrderClass> Orders { get; set; }
public MySqlDbContext(IDbConnection connection)
: base((DbConnection)connection, false)
{
Database.SetInitializer<MySqlDbContext>(null);
}
}
- . MS- ( Oracle DateTime). - "" - , . .Net- "" -properties, .
-
[Table("TORDERS")]
public class MyOrderClass
{
[Column("ORDERID")]
public long Id { get; set; }
[Column("CREATED")]
public string CreatedString { get; set; }
[NotMapped]
public DateTime? Created
{
get
{
DateTime tmp;
if (DateTime.TryParse(this.CreatedString, out tmp))
return tmp;
return null;
}
set
{
this.CreatedString = value.HasValue ? value.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
}
}
}
static void Main(params string[] args)
{
MyOrderClass tmp = new MyOrderClass() { CreatedString = "2018-01-01 11:11:11"};
Console.WriteLine(tmp.Created.ToString());
tmp.Created = null;
Console.WriteLine(tmp.CreatedString);
tmp.Created = new DateTime(2018,02,02,10,10,10);
Console.WriteLine(tmp.CreatedString);
}
Im , , EF.
db, db-, - , ;).