This project is read-only.

Override auto mapping Hibernate Id

Topics: Writing modules
Jul 12, 2013 at 8:56 PM
Edited Jul 12, 2013 at 9:04 PM
I would like to set the Id of table record from my module.
If id non auto-increment and i set Id from my module, i get error that Id can not be null on saving.
How can i fix it?

Record class:
public class CrosspostingPartRecord
 pblic virtual int Id { get; set; }
I try:
public class CrosspostingPartAlteration : IAutoMappingAlteration
        public void Alter(AutoPersistenceModel model)
            model.Override<CrosspostingPartRecord>(mapping => {
                mapping.Id(x => x.Id).GeneratedBy.Assigned();
    public class CrosspostingPartOverride : IAutoMappingOverride<CrosspostingPartRecord>
        public void Override(AutoMapping<CrosspostingPartRecord> mapping)
            mapping.Id(x => x.Id).GeneratedBy.Assigned();
but it doesnt work. Please, help.
Jul 12, 2013 at 9:02 PM
You can't; Orchard needs to be in charge of that ID; it's how part records are linked with their content item records.
Jul 12, 2013 at 9:10 PM
Edited Jul 12, 2013 at 9:11 PM
I do not inherit my record class from ContentPartRecord. And i dont add this class (part) to Content Type.
Jul 12, 2013 at 9:34 PM
You're right. It was my assumption because you have the "Part" word in it.
Then I don't know, sorry.
Jul 12, 2013 at 11:57 PM
For Id might use ISessionLocator instead of IRepository.
var session = _sessionLocator.For(typeof(CrosspostingPartRecord));
session.Save(crosspostingPart, crosspostingPart.Id);
But i think that IAutoMappingAlteration doesnt work it is bag.