如何创建可以转换为DateTime的类.但是,当它打包时,我需要投我的课.例如:
object date1 = new MyDateTime();
DateTime date2 = (DateTime)date1;
Run Code Online (Sandbox Code Playgroud)
我需要直接这个工作的例子.
我知道怎么做,但我的方式将无需包装.我不确定是否有办法做到这一点.
请帮忙.
PS.我需要直接将对象转换为DateTime.因此,MyDateTime必须先包装好.显式效果很好,但是如果你有打包对象则没有用.它必须使用普通的铸造像
(DateTime) (object) MyDateTime
Run Code Online (Sandbox Code Playgroud) 我试图在Entity Framework中向我的实体插入行.它适用于第一次插入操作,但它不适用于第二次插入操作.我使用Framework 4,C#和FireBird数据库.这是我的代码部分
rec = new T_MEDIAPLAN_REC();
//
//... initialization for T_MEDIAPLAN_REC
//
BossTVEntities.AddToT_MEDIAPLAN_REC(rec);
BossTVEntities.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
它在第二次SaveChanges()调用后给出了这个异常:
"The changes to the database were committed successfully, but an error occurred
while updating the object context. The ObjectContext might be in an inconsistent
state. Inner exception message: AcceptChanges cannot continue because the
object's key values conflict with another object in the ObjectStateManager.
Make sure that the key values are unique before calling AcceptChanges."
Run Code Online (Sandbox Code Playgroud)
我试着看看DataBase.目标实体中有两个插入的记录具有不同的Id.所以,我不知道这种行为的原因是什么.
我使用Visual Studio 2010 SP1 Professional,Firebird 2.5和.NET提供程序,C#,.NET Framework 4.0
它不适用于数据库中的每个实体.