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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:36:37+00:00 2026-05-31T17:36:37+00:00

Recently i’ve picked up my EF 4.1 / MVC 3 project again and started

  • 0

Recently i’ve picked up my EF 4.1 / MVC 3 project again and started building in actual frontend capabilities.

Now i’m developing a “simple” message system but upon going to that page i get the error as stated in the title

EDIT

It creates the database just not the models.

Stack trace:

[NullReferenceException: Object reference not set to an instance of an
object.] ASP._Page_Views_Inbox_Index_cshtml.Execute() in
c:\Development\MVC\DOCCL\Views\Inbox\Index.cshtml:18
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,
TextWriter writer, Object instance) +222
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext
viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
+295 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext
controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c_DisplayClass1c.b_19()
+23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
filter, ResultExecutingContext preContext, Func1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
+21 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
controllerContext, IList
1 filters, ActionResult actionResult) +177
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName) +324
System.Web.Mvc.Controller.ExecuteCore() +106
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
+91 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
requestContext) +10
System.Web.Mvc.<>c_DisplayClassb.b_5() +34
System.Web.Mvc.Async.<>c_DisplayClass1.b_0() +19
System.Web.Mvc.Async.<>c_DisplayClass81.<BeginSynchronous>b__7(IAsyncResult
_) +10 System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62 System.Web.Mvc.<>c
_DisplayClasse.b_d() +48
System.Web.Mvc.SecurityUtil.b
_0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
+22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+9478661 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +178

InnerException :
{“A column ID occurred more than once in the specification.”}

The recently added code is.

Controller:

//
// GET: /Inbox/Index/5/1
public ActionResult Index(int? Id, int Page = 1)
{
    try
    {
        const int pageSize = 10;
        var messages = from m in horseTracker.Messages
                        where m.ReceiverId.Equals(Id)
                        select m;

        var paginatedMessages = new PaginatedList<Message>(messages, Page, pageSize);

        return View(paginatedMessages);
    }
    catch (Exception ex)
    {

    }
    return View();
}

Models

public class Message
{
    [Key]
    public int Id { get; set; }

    [Required(ErrorMessage = "Subject is required")]
    [Display(Name = "Subject")]
    public string Subject { get; set; }

    [Required(ErrorMessage = "Message is required")]
    [Display(Name = "Message")]
    public string Content { get; set; }

    [Required]
    [Display(Name = "Date")]
    public DateTime Created { get; set; }

    public Boolean Read { get; set; }

    [Required(ErrorMessage = "Can't create a message without a user")]
    public int SenderId { get; set; }
    public virtual User Sender { get; set; }

    [Required(ErrorMessage = "Please pick a recipient")]
    public int ReceiverId { get; set; }
    public virtual User Receiver { get; set; }
}

public class User
{
    [Key]
    public int Id { get; set; }

    [Required]
    [Display(Name = "Username")]
    public string UserName { get; set; }

    [Required]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [Display(Name = "E-Mail")]
    public string Email { get; set; }

    [Required]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Required]
    [Display(Name = "Country")]
    public string Country { get; set; }

    public string EMail { get; set; }

    //Races
    public virtual ICollection<Message> Messages { get; set; }
}

modelBuilder.Entity<User>()
    .HasMany(u => u.Messages)
    .WithRequired(m => m.Receiver)
    .HasForeignKey(m => m.ReceiverId)
    .WillCascadeOnDelete(false);

Anyone have a clue on why i might be getting that error?
Before i added these classes it was working fine.

  • 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-05-31T17:36:39+00:00Added an answer on May 31, 2026 at 5:36 pm

    In your Message Model, Id is not nullable, but your action allows nulls, EF cant match these two types up in the where clause in your query & throw an exception.

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

Sidebar

Related Questions

Recently I've been doing quite the project mostly working with the DateTime class. Now,..
recently I started a small Django project that I developed on a local machine
Recently started with ASP.NET and MVC and have a few questions on working with
Recently, I started changing some of our applications to support MS SQL Server as
recently I started using storyboard and I've the following situation: I want to set
Recently two users of our software from the same company started experiencing random closures
Recently downloaded some code for a minor open-source project related to a small webgame
Recently in a project, I had a multiprocessing Process that crashed. A child process
Recently I have migrated my project from SQLServer 2000 to MySQL 5.2 using MySQL
Recently I started working with RAD and WebSphere on development of web services and

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.