我在C#Visual Studio中有一个使用EF连接到MySQL数据库的项目。 EF映射器给了我一个从MySQL视图映射的类"enteredtickets"
。我的问题是,有一个属性调用TicketDate
,数据类型是System.DateTime吗?与MySQL一样,日期可能为null。问题是我想要一个System.DateTime。
因此,我想更改EF映射类的工厂代码,以使完成的属性TicketDate
成为System.DateTime。但是,我对更改密码时的更改保持谨慎!
从阅读中我猜我需要一个类似的陈述
datetime??new DateTime(2000,1,1)
所以我的问题是
EF映射的工厂代码为
public Nullable<global::System.DateTime> TicketDate
{
get
{
return _TicketDate;
}
set
{
OnTicketDateChanging(value);
ReportPropertyChanging("TicketDate");
_TicketDate = StructuralObject.SetValidValue(value);
ReportPropertyChanged("TicketDate");
OnTicketDateChanged();
}
}
private Nullable<global::System.DateTime> _TicketDate;
partial void OnTicketDateChanging(Nullable<global::System.DateTime> value);
partial void OnTicketDateChanged();
视图所基于的MySQL表中的column属性是
TABLE `ticket` CHANGE `created` `created` DATETIME NOT NULL;
***其他信息**** 为了进一步阐明MySQL视图的细节,
select `a`.`ticket_id` AS `ticket_id`,`a`.`status` AS `status`,`a`.`number` AS `number`,`b`.`subject` AS `subject`,`b`.`timespent` AS `timespent`,`a`.`staff_id` AS `staff_id`,`a`.`user_id` AS `user_id`,(case when isnull(`b`.`dayoffset`) then `a`.`created` else (`a`.`created` + interval ceiling(`b`.`dayoffset`) day) end) AS `TicketDate`,`b`.`sysdowntime` AS `sysdowntime`,`b`.`CliDowntime` AS `CliDowntime`,`b`.`TelDowntime` AS `TelDowntime`,`b`.`NetDowntime` AS `NetDowntime`,date_format((case when isnull(`b`.`dayoffset`) then `a`.`created` else (`a`.`created` + interval ceiling(`b`.`dayoffset`) day) end),'%Y%m%d') AS `groupingdate`,`b`.`priority_id` AS `priority_id` from (`ost`.`ost_ticket` `a` join `ost`.`ost_ticket__cdata` `b` on((`a`.`ticket_id` = `b`.`ticket_id`)))
无论如何查看MySQL中的定义,视图都允许TicketDate
为Null,不确定如何停止此操作