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

  • SEARCH
  • Home
  • 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 8721769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:16:26+00:00 2026-06-13T07:16:26+00:00

I have just updated my MVC3 project (with C#) from ObjectContext to DbContext ,

  • 0

I have just updated my MVC3 project (with C#) from ObjectContext to DbContext, but I’m getting some weird error…

I’m using the database-first approach, and I have an table with a Name column of type nvarchar, that was not null. I changed it to accept null in SQL Server, then I updated my edmx model, deleted the .tt files and generated it again (with ADO.NET DbContext).

When I create a new object from that table, setting value to Name property to null I get an DbEntityValidationException with The Name field is required message in db.SaveChanges().

But the table is accepting NULL on Name column! I already inserted many rows with SQL in SQL Server with NULL in Name column!

Anyone knows how can I solve that?

Some information

Here is my table SQL:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Pre_Register](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](64) NULL,
    [Email] [nvarchar](64) NOT NULL,
    [Permission] [tinyint] NOT NULL,
    [Password] [nvarchar](256) NOT NULL
PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

This is the automatic generated model class:

public partial class Pre_Register
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public byte Permission { get; set; }
    public string Password { get; set; }
}

And here is how I get the error:

Pre_Register preReg = new Pre_Register();

db.Pre_Register.Add(preReg);

preReg.Email = "dudu@mail.com";
preReg.Permission = 1;
preReg.Password = "123456";
preReg.Name = null;

// here it comes
db.SaveChanges();
  • 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-13T07:16:27+00:00Added an answer on June 13, 2026 at 7:16 am

    The only thing i see :

    Open your edmx.

    Go to your Pre_Register entity, select your Name property, right click, properties, and check if Nullable field is set to true.

    If it’s not, set it to true. This would be strange, but I can’t find another reason.

    enter image description here

    This would mean that DataBase first is… not perfect, or that something happened on your side…

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

Sidebar

Related Questions

I just updated an app from .NET 2.0 to .NET 4.0 and I have
I currently have an app published on the App Store but I've just updated
I've just updated a mvc 2 project to mvc 3 . I have the
I have just updated to using EF 4.0 where before i was using Linq
We have just updated our application from ASP.Net 2.0 to ASP.Net 4.0. We have
I have just updated my version of NewtonSoft JSON.NET from version 3.0.0 to 3.5.0
I have just created a new MVC 3 project and updated all the installed
Trying to get my project updated to MVC3, something I just can't find: I
I just started an MVC 3 project using Forms Authentication. I have a web
We have some files stored in sql database. On an ASP.NET MVC3 form, we

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.