
我的模型的一个方法primaryKey是'PlanetKey‘
Graph graph = new Graph();
long lastGraphID = 1000;
//graph.GraphID = lastGraphID;
graph.ItemType = enumType;
graph.GraphItemTitle = title;
graph.GraphItemDescription = statusMessage;
graph.GraphItemUserFullName = null;
graph.GraphItemURL = url;
graph.ItemSummary = title + ": " + statusMessage; ;
graph.ItemCreatedOn = DateTime.UtcNow.ToLocalTime();
//graph.GraphID = lastGraphID;
graph.GraphCustomURL = null;
graph.DbType = "OFFLINE";
graph.ItemOwnerGraphID = ItemOwnerGraphID;
graph.ItemUserID = userInfoId;
graph.PRIMARYTaggedAcademicTreeNodeId = 0;
graph.PRIMARYTaggedAcademicTreeSerialNumber = "1";
graph.PRIMARYTaggedCareerTreeNodeId = 0;
graph.PRIMARYTaggedCareerTreeSerialNumber = "1";
graph.PRIMARYTaggedSkillTreeNodeId = 0;
graph.PRIMARYTaggedSkillTreeSerialNumber = "1";
graph.PRIMARYTaggedAcademicTreeNodeId = 0;
graph.PRIMARYTaggedAcademicTreeSerialNumber = "1";
graph.PRIMARYTaggedToolTreeNodeId = 0;
graph.PRIMARYTaggedToolTreeSerialNumber = "1";
graph.CountReactions = 0;
graph.CountResponses = 0;
graph.CountRatings = 0;
graph.AverageRating = 0;
graph.CountRatings = 0;
graph.CountUses = 0;
graph.CountViews = 0;
graph.isReported = false;
graph.isPSKverified = false;
graph.isPSKbanned = false;
graph.isPSKresource = false;
graph.AccessAllowedCode = 0;
graph.AgeRestrictionCode = loginUserCurrentAge;
graph.isHidden = false;
GraphsController GraphsControllerObject = new GraphsController();
long returnGraphId = GraphsControllerObject.CreateGraphIdByModel(graph);这是我打电话来的另一个目的
public long CreateGraphIdByModel(Graph graph)
{
try
{
if (ModelState.IsValid)
{
db.Graphs.Add(graph);
db.SaveChanges();
return graph.GraphID;
}
}
catch (DataException)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
}
return graph.GraphID;
}这向我展示了db.SaveChanges()中的错误。我在这段代码中做错了什么?我只想使用模型作为mvc4的crud来传递参数

发布于 2014-03-06 04:51:24
要知道错误是什么:您需要查看内部异常,它将准确地告诉您问题是什么。
您可以检查exceptions innerException属性。它将是一个包含错误列表的EF异常。
错误显示为,Error converting datetime2 to datetime
实体框架将所有日期作为Datetime2处理,因此,如果数据库中的字段是Datetime,这可能是一个问题。填充所有日期字段和更改数据类型是最常见的解决方案
从这里复制:'datetime2' error when using entity framework in VS 2010 .net 4.0
https://stackoverflow.com/questions/22208731
复制相似问题