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 7761057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:03:09+00:00 2026-06-01T14:03:09+00:00

I get a NullReferenceException when my target provider is SQL Server CE, but with

  • 0

I get a NullReferenceException when my target provider is SQL Server CE, but with SQL Server Express it works. I get the exception on the return... when I’m trying to access the Comments. Model is very simple and it can be inferred from the code. Thanks for any help! I’m using Entity Framework code-first 4.3 and SQL Server CE 4.0 by the way.

  • using the same code with SQL Server Express as provider = runs fine

  • using the same code with SQL Server CE as provider = exception error

In addition, I have no problems with SQL Server CE. It works on my machine and I have done single-table operations with Entity Framework code-first and even asp.net authorization. I have never done any nested addition/deletion like this on related entities though so I’m curious as to why this doesn’t work..

            db.Persons.Add(new Person()
            {
                FullName = "JC Viray",
                Comments = new List<Comment>(){
                         new Comment(){CommentContent="Hello!"},
                         new Comment(){CommentContent="World!"}
            }
            });

            db.SaveChanges();

            return db.Persons.FirstOrDefault().Comments.FirstOrDefault().CommentContent;

What stumps me also is that in SQL Server Express, if I examine the data, the comments are there.

In SQL Server CE, only the Persons table has data while the Comments table is empty.

EDIT:

If it helps, here is the model:

    public class Person
{
    [Key]
    public int PersonId { get; set; }
    public string FullName { get; set; }

    public virtual ICollection<Comment> Comments { get; set; }
}

public class Comment
{
    [Key]
    public int CommentId { get; set; }
    public string CommentContent { get; set; }

    [ForeignKey("Person")]
    public int PersonId { get; set; }
    public virtual Person Person { get; set; }
}
  • 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-01T14:03:10+00:00Added an answer on June 1, 2026 at 2:03 pm

    The problem is that: SQL CE error details are a lot more vague than when using SQL Server Express as provider therefore the confusion and the vague direction.

    SQLCE Exception details is something like:

    NullException

    SQLExpress Exception details is something like:

    The model backing the ‘MyContext’ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

    The solution is: to sync the models by adding this code:

    Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

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

Sidebar

Related Questions

I'm trying to add ConfirmDialogHandler to dialog handler and i get NullReferenceException. This happens
I get a NullReferenceException when trying to append element to its parent to element,
I have some problem with MvcSiteMap. I get NullreferenceException when interating over Model.Nodes because
So, I get a NullReferenceException thrown on a production server. It's not reproducible and
Whenever I run my program, I get: NullReferenceException was unhandled, Object Reference not set
I get an Access is Denied error message when I use the strong name
How can I get a NullReferenceException in the following scenario? Dim langs As IEnumerable(Of
I'm trying to get a reference to the user object in my Global.asax file's
I have problem with testing classes, which using UpdateModel() method. I get System.NullReferenceException. I
I'm trying JQGrid ASP.NET MVC2 version. Created a model and the controller: var itemsGridModel

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.