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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:19:08+00:00 2026-06-09T08:19:08+00:00

I have created a module that i want to collect some simple data in

  • 0

I have created a module that i want to collect some simple data in Orchard’s database, so i have created model, migration and handler for it:

Models/StatePartRecord.cs :

 namespace Address.Models
    {
        public class StatePart : ContentPart<StatePartRecord>
        {
            public int Id
            {
                get { return Record.Id; }
                set { Record.Id = value; }
            }
            public string StateName
            {
                get { return Record.StateName; }
                set { Record.StateName = value; }
            }
        }
    }

Models/StatePartRecord.cs :

namespace Address.Models
{
    public class StatePartRecord : ContentPartRecord
    {
        public virtual int Id { get; set; }
        public virtual string StateName { get; set; }
    }
}

Migrations.cs :

namespace Address
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable("StatePartRecord", table => table
                .ContentPartRecord()
                .Column<string>("StateName")
                );

            return 1;
        }
        public int UpdateFrom1()
        {
            ContentDefinitionManager.AlterPartDefinition("State", part => part
                .Attachable());

            return 2;
        }

    }
}

Handlers/StatePartHandler.cs :

namespace Address.Handlers
{
    public class StatePartHandler : ContentHandler
    {
        public StatePartHandler(IRepository<StatePartRecord> repository)
        {
            Filters.Add(StorageFilter.For(repository));
        }
    }
}

Services/MyService.cs :

namespace Address.Services
{
    public class AddressService : IAddressService
    {
    ...
     public void InsertState(Models.StatePartRecord state)
     {
         _stateRepository.Create(state);
     }
    ...
}

now in written service class for my module, when i try to create an item and save it in database it trows an exeption:

attempted to assign id from null one-to-one property: ContentItemRecord

Note that _stateRepository is a IRepository<StatePartRecord> typed injected object.

what is wong?

  • 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-09T08:19:10+00:00Added an answer on June 9, 2026 at 8:19 am

    This is because ContentPartRecord has a ContentItemRecord property that points to the ContentItemRecord corresponding to the content item the ContentPartRecord’s Part is attached to.

    You don’t have to manage part records directly: Orchard services (mainly ContentManager) does this for you. Even if you want to modify records on a lower level you should do this through ContentManager (by injecting an IContentManager). Only manipulate records directly if they’re just “plain” records you use to store non-content data, i.e. that aren’t ContentPartRecords.

            // MyType is a content type having StatePart attached
            var item = _contentManager.New("MyType");
    
            // Setting parts is possible directly like this.
            // NOTE that this is only possible if the part has a driver (even if it's empty)!
            item.As<StatePart>().StateName = "California";
    
            _contentManager.Create(item);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple Python module and want to distribute it with pip.
Very simple problem: I have a Public Sub (in a module) that I want
I have created a class called Class1, and in another module, I want to
I have created a module in access 2007 that will update linked tables, but
I have created a simple GAE app based on the default template. I want
I created one module in Magento. I create Api.php in that. Now I want
I have created a custom module and am using hook_block to programmatically create some
I want to add user authentication to my restful api that I have created
I have a bit of data that I want to use to build a
I have a module that uses multithreading. I want to store the number of

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.