0

enter image description hereThis my one method primaryKey of my model is '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);

this is another what i am calling to

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;
        }

this is showing me eeror in db.SaveChanges() what m i doing wrong with this code i just wanna pass my parameter using model as crud of mvc4

enter image description here

8
  • What error is it showing, exactly? Commented Mar 5, 2014 at 20:43
  • You should probably have some way to capture the actual exception to get a better idea of what is happening rather than just displaying a generic message. Commented Mar 5, 2014 at 20:44
  • An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code Commented Mar 5, 2014 at 20:45
  • @VipsSaini "See the inner exception for details". Could you please add that info? Commented Mar 5, 2014 at 20:48
  • 1
    We can't tell you why you're getting the error until we know what the error is! It could be anything from a formatting error to your database server exploding. Commented Mar 5, 2014 at 20:51

1 Answer 1

0

To know what the error is: You need to look at the inner exception, it will tell you precisely what the problem is.

You can inspect the exceptions innerException property. It will be an EF exception with a list of errors.

The error says, Error converting datetime2 to datetime

Entity framework handles all the dates as a Datetime2, so, if you fields in the database are Datetime, this could be a problem. Populating all the date fields and changing the datatype, are the most commom solutions

Copied from here: 'datetime2' error when using entity framework in VS 2010 .net 4.0

Sign up to request clarification or add additional context in comments.

1 Comment

figure out what value you are sending... learn why that value cannot convert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.