Solved

entity framework can't insert null error on generated id column

Posted on 2013-01-12
1
1,699 Views
Last Modified: 2013-01-18
I have a strange issue where I started getting an error trying to insert into a table.  

Cannot insert the value NULL into column 'Id', table 'OptionSettlementValues'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Here is the code for that object
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid Id { get; set; }
        public string UnderlyingSymbol { get; set; }
        public DateTime Expiration { get; set; }
        public decimal SettlementPriceUnderlying { get; set; }
        public string Type { get; set; }

        public OptionSettlementValue()
        {}

        public OptionSettlementValue(string underlyingSymbol, string expiration, string settlementPriceUnderlying, string type)
        {
            UnderlyingSymbol = underlyingSymbol;
            Expiration = DateTime.Parse(expiration);
            SettlementPriceUnderlying = decimal.Parse(settlementPriceUnderlying);
            Type = type;
        }


Here is my code to insert:
var db = new Context("JTradeAdmin");
db.OptionSettlementValue.Add(new OptionSettlementValue("OEX", "1/4/2013", "664.69", "weekly"));
db.SaveChanges();
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
TempDBA earned 500 total points
ID: 38771096
You need to see in your table structure, if any constraint is defined for ID column which is of type guid, that by default, any value is defined to be populated into it or not. I think there is no default value and it needs you to pass it from your program using some function that populates GUID values.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question