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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:06:20+00:00 2026-06-08T11:06:20+00:00

I have declared some Non-Content data in an Orchard CMS by defining the records

  • 0

I have declared some Non-Content data in an Orchard CMS by defining the records and schema like this:

public class CountyRecord
{
    public virtual int Id { get; set; }
    public virtual string CountyName { get; set; }
    public virtual CountryRecord CountryRecord { get; set; }
}

public class CountryRecord
{
    public CountryRecord()
    {
        CountyRecords = new List<CountyRecord>();
    }
    public virtual int Id { get; set; }
    public virtual string CountryName { get; set; }
    public virtual IList<CountyRecord> CountyRecords { get; set; }
}

public class Migrations: DataMigrationImpl
{
    public int Create()
    {
        //COUNTIES
        SchemaBuilder.CreateTable(typeof(CountyRecord).Name, table => table
            .Column<int>("Id", col => col
                .PrimaryKey()
                .Identity())
            .Column<string>("CountyName")
            .Column<int>("CountryRecord_Id"));

        //COUNTRIES
        SchemaBuilder.CreateTable(typeof(CountryRecord).Name, table => table
            .Column<int>("Id", col => col
                .PrimaryKey()
                .Identity())
            .Column<string>("CountryName"));
    }
}

I then have two controllers handling the admin pages for these two entities. In the country controller I have the following actions:

    //DELETE
    [HttpGet, Admin]
    public ActionResult Delete(int countryId)
    {
        var country = CountryRepo.Get(countryId);
        if (country == null)
        {
            return new HttpNotFoundResult("Couldn't find the country with ID " + countryId.ToString());
        }
        return View(country);
    }

    [HttpPost, Admin, ActionName("Delete")]
    public ActionResult DeletePOST(CountryRecord country)
    {       
        foreach (CountyRecord county in CountyRepo.Fetch(c=>c.CountryRecord.Id==country.Id))
        {
            CountyRepo.Delete(county);
        }

        CountryRepo.Delete(country);
        OrchardServices.Notifier.Add(NotifyType.Information, T("Country '{0}' deleted successfully", country.CountryName));
        return RedirectToAction("Index");
    }

And this is the view that goes with that:

@model Addresses.Models.CountryRecord
<div class="manage">
@using (Html.BeginFormAntiForgeryPost("Delete"))
{
    <h2>Are you sure you want to delete this country and ALL its counties?</h2>
    @Html.HiddenFor(m => m.Id);
    @Html.HiddenFor(m => m.CountryName);
    @Html.ActionLink(T("Cancel").Text, "Index", "CountriesAdmin", new { AreaRegistration = "Addresses" }, new { style = "float:right; padding:4px 15px;" })
    <button class="button primaryAction" style="float:right;">@T("Confirm")</button>
}
</div>

However, here’s the issue, when I delete a country that still has counties assigned to it, it throws the following error:

a different object with the same identifier value was already associated with the session

Can anyone please help?

Thanks.

  • 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-08T11:06:21+00:00Added an answer on June 8, 2026 at 11:06 am

    It’s because your DeletePOST() parameter is a CountryRecord. Orchard records are all proxied by the NHibernate framework and MVC’s ModelBinder can’t properly create them for you.

    What you need to do instead is like what you do in the non-POST method: accept just the integer ID of the CountryRecord, fetch the record fresh from the repository, then delete it.

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

Sidebar

Related Questions

Let's say we have a class that looks like this: class A { public:
I have a div with float:right (no position property declared). This div has some
I have declared a variable like this @{ int i = 1; } Now,
I have declared std::priority_queue like this. priority_queue < Aircraft, vector<Aircraft>, less<Aircraft> > *q; And
I have a windows forms application, where I have declared some static variables. On
I have declared one variable in xslt, assigned some value to it but while
So I have a chunk of code that declares some classes, creates data, uses
I have a class IDocument which serve as a interface for some classes. It
If I have a class Product: public class Product { public string Title {
I have this call in UIViewController-inheritor class context: + (void) smthPressed: (id) caller {

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.