Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:52:01+00:00 2026-06-02T17:52:01+00:00

Problems when saving object in LINQ/C# when i try to save a new record

  • 0

Problems when saving object in LINQ/C#

when i try to save a new record i get this error:

Cannot insert the value NULL into column 'EmpresaID', table 'mydb.dbo.Empresa'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Was Made the table with SQL Server Management Studio 2012

USE [mydb]
GO

/****** Object:  Table [dbo].[Empresa]    Script Date: 25/04/2012 03:40:00 p.m. ******/
DROP TABLE [dbo].[Empresa]
GO

/****** Object:  Table [dbo].[Empresa]    Script Date: 25/04/2012 03:40:00 p.m. ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Empresa](
    [EmpresaID] [int] NOT NULL,
    [RazonSocial] [nvarchar](210) NOT NULL,
    [Nit] [nchar](20) NOT NULL,
 CONSTRAINT [PK_Empresa] PRIMARY KEY CLUSTERED 
(
    [EmpresaID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

i made a class for handle the data

[Table(Name = "Empresa")]
class Empresa
{
    private int _EmpresaID;
    private string _RazonSocial;
    private string _Nit;

    [Column(DbType = "int", IsPrimaryKey = true, IsDbGenerated = true)]
    public int EmpresaID
    {
        set { _EmpresaID = value; }
        get { return _EmpresaID; }
    }

    [Column(DbType = "nvarchar(210)", CanBeNull = false)]
    public string RazonSocial
    {
        set { _RazonSocial = value; }
        get { return _RazonSocial; }
    }

    [Column(DbType = "nchar(20)", CanBeNull = false)]
    public string Nit
    {
        set { _Nit = value; }
        get { return _Nit; }
    }

}

made and which method is this:

Entity.Empresa empresa = new Entity.Empresa() {                
    Nit = NuevaEmpresaNitTxtBox.Text,
    RazonSocial = NuevaEmpresaRazonSocialTxtBox.Text
};

MyDataContext.GetTable<Entity.Empresa>().InsertOnSubmit(empresa);
MyDataContext.SubmitChanges();

can tell me was worng with my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:52:02+00:00Added an answer on June 2, 2026 at 5:52 pm

    You forgot to declare Identity on EmpressaId. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems while saving a pre-persisted JDO object in google-app-engine data store.
I see a similar question in Problems while saving a pre-persisted object in Google
i've got problems using the NSKeyedArchiver/NSKeyedUnarchiver for saving my object. I added the methods
Being new to Linq-to-SQL, I ran into one of it's Gotchas today and I
I having problems saving many to many relationships to a pivot table. The way
In this question I was having problem with saving objects that had foreign keys
I am having a problem saving the Parent object which contains multiple children. The
Microsoft has made saving objects very easy with their LINQ to SQL mapping. However,
So I am having problems saving collections unique across tabs/browser (tabs really). Using static
Joomla 1.5.25 just upgraded from 1.5.23 having problems saving to session and persistency, works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.