Solved

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

Posted on 2013-01-12
1
1,682 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2012 AOG and SQL2014 AOG 76 61
getting error while running below query  in sql 2 16
SQL syntax question 6 42
calculate running total 8 9
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

749 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