nhibernate - Orchard CMS ISessionConfigurationEvents and 1:N, N:N Relationships? -


i have spent many days trying implement relationships within orchardcms 1.9.1 between custom contentparts no avail. strewn across internet many others trying achieve same thing, have failed; giving me impression it's impossible? though read article at: http://www.ideliverable.com/blog/isessionconfigurationevents gave impression things possible fluent nhibernate should possible within orchard.

so implemented:

public class dbmapping : isessionconfigurationevents {     public void created(fluentconfiguration cfg, autopersistencemodel defaultmodel)     {         defaultmodel.useoverridesfromassemblyof<profilepartrecord>().alterations(x => x.addfromassemblyof<profileoverride>());         defaultmodel.useoverridesfromassemblyof<locationpartrecord>().alterations(x => x.addfromassemblyof<locationoverride>());     }      public void prepared(fluentconfiguration cfg) { }     public void building(configuration cfg) { }     public void finished(configuration cfg) { }     public void computinghash(hash hash) { } }    public class locationoverride : iautomappingoverride<locationpartrecord> {     public void override(automapping<locationpartrecord> mapping)     {         //[ profile ] <--> [ location ]         //mapping.id(x => x.id, "locationpartrecord_id"); //as it's not in model due being contentpart, nh throw error because of such.         mapping.map(x => x.type);         mapping.map(x => x.name);         mapping.references(x => x.profilepartrecord, "profilepartrecord_id");     } }   public class profileoverride : iautomappingoverride<profilepartrecord> {     public void override(automapping<profilepartrecord> mapping)     {         //[ profile ] 0.1 <---> n [ location ]         //new         mapping.hasmany(x => x.locations)             .inverse()             //.keycolumn("profilepartrecord_id")             .cascade.all()             .foreignkeycascadeondelete()              .foreignkeyconstraintname("fk_location__profile");      } } 

models:

public class profilepartrecord : contentpartrecord {     public virtual string firstname { get; set; }     public virtual string lastname { get; set; }      [cascadealldeleteorphan]     public virtual ilist<locationpartrecord> locations { get; set; }     public profilepartrecord()     {         locations = new list<locationpartrecord>();     } }   public class locationpartrecord : contentpartrecord {     public virtual string type { get; set; }     public virtual string name { get; set; }      //for hasmany     [cascadealldeleteorphan]     public virtual profilepartrecord profilepartrecord { get; set; } } 

migration:

        schemabuilder.createtable("profilepartrecord",             table => table                 .contentpartrecord()                 //pk: profilepartrecord_id                 .column<string>("firstname")                 .column<string>("lastname")                 //system                 .column<datetime>("createdat")             );          contentdefinitionmanager.alterpartdefinition("profilepart",             builder => builder.attachable());          contentdefinitionmanager.altertypedefinition("profile", t => t             .withpart(typeof(profilepart).name)             .withpart("userpart")             );          contentdefinitionmanager.altertypedefinition("user", t => t             .withpart("profilepart")             );            schemabuilder.createtable("locationpartrecord",             table => table                 .contentpartrecord()                 //pk: locationpartrecord_id                 //fk:                 .column<int>("profilepartrecord_id")                 .column<string>("type")                 .column<string>("name")                 //system                 .column<datetime>("createdat")             );          contentdefinitionmanager.alterpartdefinition("locationpart",             builder => builder.attachable());          contentdefinitionmanager.altertypedefinition("location", type => type             .withpart("commonpart")             .withpart("locationpart")             .creatable()             .listable()); 

but alas, still can't create relationship between these 2 entities. can such via migration, limited - in - can't set relationship cascade.

can shed light on whether possible, , if so, how? thanks

this may not whole way, believe help. 1 thing have done performance reasons establish relationships @ database level between parts use "createforeignkey" , "createindex" in migration. here example should work you

// add foreign key schemabuilder.createforeignkey(     "fk_locationprofile",     "locationpartrecord", new[] { "profilepartrecord_id" },     "profilepartrecord", new[] { "id" });  // add index schemabuilder.altertable("locationpartrecord",     table => table         .createindex("idx_profilepartrecord_id", "profilepartrecord_id")     ); 

with these relationships defined, wonder if in way impact nhibernate work doing.

as how have done overall goal believe trying achieve, can monitor "profilepart" "delete" event in "locationpart" handler , apply own cascading delete logic there ensure there no "locationpart" left around.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -