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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:23:56+00:00 2026-05-17T15:23:56+00:00

I have been dealing with this for at least two days now. I don’t

  • 0

I have been dealing with this for at least two days now. I don’t have a book available to reference, and I cannot for the life of me find an explanation of how this is supposed to work.

What I am trying to do is a simple operation:

  1. Load a create form populated with 3 dropdownlist elements which reference other tables
  2. Fill out the form
  3. Submit the form and save the entity

I have tried every way I can think of to get this to work. This should be easy. I have tried it with and without a ViewModel. I think it’s clearer without the ViewModel

Note: Due to requirements, I am using .NET 3.5. Does this mean I am on an older version of EF?

Another Note: Yes, I am using VB. No, that is not my choice.

Controller:

    Function Create() As ActionResult
        PopulateForm()
        Return View()
    End Function

    <HttpPost()>
    Function Create(ByVal escalation As Escalation) As ActionResult
        If TryUpdateModel(escalation) Then
            repo.AddEscalation(escalation)
            repo.Save()
            Return RedirectToAction("Details", New With {.Id = escalation.Id})
        End If

        'The model did not save - there are validation errors'
        PopulateForm()
        Return View()
    End Function

    Private Sub PopulateForm()
        ViewData("categoryList") = repo.GetAllCategories().ToList()
        ViewData("statusList") = repo.GetAllStatuses().ToList()
        ViewData("pathList") = New List(Of Path)
    End Sub

Repository:

Public Sub AddEscalation(ByVal esc As Escalation)
    esc.Created_At = DateTime.Now()
    entities.AddToEscalations(esc)
End Sub

Public Sub Save()
    entities.SaveChanges()
End Sub

View:

        <div class="editor-label">
            <%= Html.LabelFor(Function(model) model.Status)%>
        </div>
        <div class="editor-field">
             <%= Html.DropDownListFor(Function(model) model.Status, New SelectList(ViewData("statusList"), "Id", "Name"))%>
             <%= Html.ValidationMessageFor(Function(model) model.Status)%>
        </div>

        <div class="editor-label">
            <%= Html.LabelFor(Function(model) model.Category)%>
        </div>
        <div class="editor-field">
            <%= Html.DropDownListFor(Function(model) model.Category, New SelectList(ViewData("categoryList"), "Id", "Name"))%>
             <%= Html.ValidationMessageFor(Function(model) model.Category)%>
        </div>

When using the DropDownListFor… model.Property, it fails in the TryUpdateModel call. The validation errors look like this in the returned form: The value ’35’ is invalid.

If I change it to DropDownListFor…model.Property.Id, it dies on SaveChanges() like so:

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

In debugging, my Escalation does have a Category, with only the Id property populated and in the Detached state.

If I do the following to populate the full objects:

Public Sub AddEscalation(ByRef esc As Escalation)
    esc.Created_At = DateTime.Now()
    esc.Category = Me.GetCategory(esc.Category.Id)
    esc.Status = Me.GetStatus(esc.Status.Id)
    esc.Path = Me.GetPath(esc.Path.Id)
    entities.AddToEscalations(esc)
End Sub

Public Function GetPath(ByVal id As Integer) As Path
    Dim path As Path = entities.Paths.FirstOrDefault(Function(c) c.Id = id)
    path.CategoryReference.Load()
    Return path
End Function

I get: Entities in ‘Escalations_Conn.Paths’ participate in the ‘FK_Paths_Categories’ relationship. 0 related ‘Category’ were found. 1 ‘Category’ is expected.

I really appreciate any help anyone has.

  • 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-17T15:23:56+00:00Added an answer on May 17, 2026 at 3:23 pm

    I appreciate all the help I was given.

    After a lot of digging, I believe the problem is that I’m using EF1 because I’m on .NET 3.5. I know Linq to SQL is kind of deprecated, but for .NET 3.5 I’m pretty sure it is far better than EF1. As such, I’ve switched my project to use Linq to SQL. And it works exactly like I would imagine. I just bind my form to the foreign key:

    <%= Html.DropDownListFor(Function(model) model.Category_Id, 
      New SelectList(ViewData("categoryList"), "Id", "Name"))%>
    

    And voila! The model saves with the correct associations!

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

Sidebar

Related Questions

I have been dealing with this situation for a while now. I have been
I have been dealing with this for a few months now. My flex apps
Sorry if this is basic, but I have been dealing with figuring this out
I have been dealing many days with a problem without any success. In my
I am a totally noob at CakePHP and have been dealing with this site
This is something I have been struggling about for some time now. The thing
I have been dealing with Nasm and GNU C inline asm on a Linux
For a period of time, I have been dealing with an issue in pagination
I've been dealing with a frustrating problem recently. I have a lot of reflection
Have been working on this question for a couple hours and have come close

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.