-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM a
PostPosted: Wed Aug 10, 2011 12:25 pm 
Newbie

Joined: Wed Aug 10, 2011 12:08 pm
Posts: 1
I'm trying to update a record using fluent nhibernate. I'm getting the error "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" on create or update. I can see that this is related to a datetime field that's being set to null. I have 4 datetime fields and are nullable in my entity. I tried to debug the code and the values are getting parsed correctly. Not sure where this is coming from. I tried to comment out all the fields and update just 1 field, still getting the same error.

Here is my code

ENTITY
Code:
public class Test
    {
        public virtual int Id { get; set; }
        public virtual int ContractLineItemId { get; set; }
        public virtual decimal TotalCostChange { get; set; }
        public virtual decimal ReqEligibleCostChange { get; set; }
        public virtual decimal EligibleCostChange { get; set; }       
        public virtual int ProjectId { get; set; }
        public virtual string Status { get; set; }
        public virtual string ActionType { get; set; }
        public virtual int? CommitmentId { get; set; }
        public virtual string CommitmentCode { get; set; }
        public virtual DateTime? DateReceived { get; set; }
        public virtual int ActionNumber { get; set; }
        public virtual float PercentageFunded { get; set; }
        public virtual DateTime? DecisionDate { get; set; }
        public virtual int DaysAdded { get; set; }
        public virtual DateTime? CompletionDate { get; set; }
        public virtual string OtherChange { get; set; }
        public virtual string OtherCostChange { get; set; }
        public virtual string Notes { get; set; }
        public virtual string ApprovedBy { get; set; }
        public virtual decimal LocalCostChange { get; set; }
        public virtual string Program { get; set; }
        public virtual DateTime? LastModified { get; set; }
        public virtual int OtherId { get; set; }
        public virtual int DetailId { get; set; }

        //public virtual ContractLineItem ContractLineItem { get; set; }
        public virtual Project Project { get; set; }
       // public virtual ProjectCommitment ProjectCommitment { get; set; }
    }


MAPPING
Code:
public class ContractLiActionMap : ClassMap<ContractLiAction>
    {
        public ContractLiActionMap()
        {
            Id(x => x.Id).Column("CoLA_Key").GeneratedBy.Assigned();
            Map(x => x.ContractLineItemId).Column("CoLi_Key1");
           
            Map(x => x.ProjectId).Column("CoLa_ProjectID").Not.Insert().Not.Update();
            References(x => x.Project, "CoLa_ProjectID");

            Map(x => x.TotalCostChange).Column("Total_Cost_Change");
            Map(x => x.ReqEligibleCostChange).Column("Req_Eligible_Cost_Change");
            Map(x => x.EligibleCostChange).Column("Eligible_Cost_Change");
            Map(x => x.Status).Column("Status");
            Map(x => x.ActionType).Column("Action_Type");

            Map(x => x.CommitmentId).Column("CoLA_Commitment_ID");//.Not.Insert().Update();
            //References(x => x.ProjectCommitment);
            Map(x => x.CommitmentCode).Column("CoLA_Commitment_Code");
            Map(x => x.DateReceived).Column("Date_Received");
            Map(x => x.ActionNumber).Column("Action_Number");   
            Map(x => x.PercentageFunded).Column("Percent_Funded");         
            Map(x => x.DecisionDate).Column("Decision_Date");
            Map(x => x.ApprovedBy).Column("Approved_By");
            Map(x => x.DaysAdded).Column("Days_Added");
            Map(x => x.CompletionDate).Column("Completion_Date");
            Map(x => x.OtherChange).Column("Other_Change");           
            Map(x => x.Notes).Column("Notes");
            Map(x => x.OtherCostChange).Column("Other_Cost_Change");
            Map(x => x.LocalCostChange).Column("Local_Cost_Change");
            Map(x => x.Program).Column("CoLa_Program");
            Map(x => x.LastModified).Column("Last_Modified");
            Map(x => x.OtherId).Column("CoLa_OtherId");
            Map(x => x.DetailId).Column("DetailId");

            Table("Contract_LI_Actions");
        }
    }


UPDATE
Code:
private ActionResult UpdateAction(int id, int otherId)
        {
            var actionJson = Request["ContractLiActions"];
            var updatedLiAction = JsonConvert.DeserializeObject<ContractLiAction>(actionJson);
            var contractLiAction = Session.Get<ContractLiAction>(updatedLiAction.Id);
            using (var transaction = Session.BeginTransaction())
            {
                contractLiAction.CommitmentId = updatedLiAction.CommitmentId > 0
                         ? updatedLiAction.CommitmentId : null;
                contractLiAction.CommitmentCode = updatedLiAction.CommitmentId > 0 ? Session.Load<ProjectCommitment>(updatedLiAction.CommitmentId).CommitmentCode : updatedLiAction.CommitmentCode;
                contractLiAction.OtherId = updatedLiAction.CommitmentId > 0 ? Session.Load<ProjectCommitment>(updatedLiAction.CommitmentId).OtherId : updatedLiAction.OtherId;
                contractLiAction.DateReceived = Convert.ToDateTime(updatedLiAction.DateReceived);
                contractLiAction.ActionNumber = updatedLiAction.ActionNumber;
                contractLiAction.ActionType = updatedLiAction.ActionType;
                contractLiAction.TotalCostChange = updatedLiAction.TotalCostChange;
                contractLiAction.ReqEligibleCostChange = updatedLiAction.ReqEligibleCostChange;
                contractLiAction.PercentageFunded = updatedLiAction.PercentageFunded;
                contractLiAction.EligibleCostChange = updatedLiAction.EligibleCostChange;
                contractLiAction.Status = updatedLiAction.Status;
                contractLiAction.DecisionDate = Convert.ToDateTime(updatedLiAction.DecisionDate);
                contractLiAction.ApprovedBy = updatedLiAction.ApprovedBy;
                contractLiAction.DaysAdded = updatedLiAction.DaysAdded;
                contractLiAction.CompletionDate = Convert.ToDateTime(updatedLiAction.CompletionDate);
                contractLiAction.OtherChange = updatedLiAction.OtherChange;
                contractLiAction.LocalCostChange = updatedLiAction.LocalCostChange;
                contractLiAction.Notes = updatedLiAction.Notes;
                contractLiAction.OtherCostChange = updatedLiAction.OtherCostChange;
                contractLiAction.LastModified = DateTime.Now;
                Session.Update(contractLiAction);

                transaction.Commit();
            }
            return GetContractLiAction(updatedLiAction.ContractLineItemId,updatedLiAction.OtherId);
        }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.