简体   繁体   中英

EF6 Code First: Fixing DateTime2

I have a code first EF6 database which contains a number of DateTime fields. These were mapped to datetime fields in the localdb database when the tables were created.

I recently introduced some time zone adjustments to the values stored in some of these fields, and now I've run into the "conversion of datetime2 to datetime" situation.

What I'd like to do is tweak the table definitions in code, do an add-migration/update-database step, and go on with my work.

But all of the answers I've seen online to this situation call for creating a convention and using the fluent api inside the data context's OnModelCreating() method.

Unfortunately, I have no experience with using the fluent api. It's not even clear to me whether OnModelCreating runs during an add-migration/update-database process.

Can this kind of migration be done by decorating DateTime properties with some attribute?

Try this u may get rid if ur issue

[DatabaseGenerated(DatabaseGeneratedOption.Identity), DataMember]
public DateTime? Registered { get; private set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM