Some unexpected errors occurred while writing the custom module. When solving these problems, we deepened our understanding of orchard development.
1. When a part is edited, the part interface is not always displayed.
Check all the files and find that the service is not added to the constructor in the partdriver class,
Original statement:
Public Class Fixedassetpartdriver: contentpartdriver <fixedassetpart> { Private Readonly Inotifier _ notifier; Private Const String Templatename = " Parts/fixedasset " ; Private Readonly Ifixedassetservice _ service; Protected Override String Prefix { Get { Return " Fixedasset " ;}} Public Localizer t { Get ; Set ;} Public Fixedassetpartdriver (inotifier notifier) // Public fixedassetpartdriver (inotifier notifier, ifixedassetservice Service) {_ Notifier = Notifier; // _ Service = service; T = Nulllocalizer. instance ;}
Updated statement:
PublicFixedassetpartdriver (inotifier notifier, ifixedassetservice Service) {_ notifier=Notifier; _ service=Service; t=Nulllocalizer. instance ;}
IfixedassetserviceThe data called by her is not instantiated, so it cannot appear, and no Part Page is displayed.
2. When updating data, the error of null ID is displayed, and no reason is found for a few days. I read the latest document and found that I did not pay attention to the details.
See the originalCode:
Public Class Fixedassetpart: contentpart <fixedassetpartrecord> { Public String Assetcode { Get { Return Record. assetcode ;} Set {Record. assetcode = Value ;}} Public String Assetname { Get { Return Record. assetname ;} Set {Record. assetname =Value ;}} Public String Brand { Get { Return Record. Brand ;} Set {Record. Brand = Value ;}} Public Decimal Assetvalue { Get { Return Record. assetvalue ;} Set {Record. assetvalue = Value ;}} Public Assetbuymethodrecord assetbuymethod { Get { Return Record. assetbuymethod ;} Set {Record. assetbuymethod = Value ;}}
Migration class:
Schemabuilder. createtable ( Typeof (Fixedassetpartrecord). Name, T => T. contentpartrecord (). Column < String > ( " Assetcode " ). Column < String > ( " Assetname " ). Column < String > (" Brand " ). Column < Decimal > ( " Assetvalue " ). Column < Int > ( " Assetbuymethodrecord_id " ));
The relationship between fixedassetpartrecord and assetbuymethodrecord is one-to-many. The columns in all fixedassetpartrecord tables should beAssetbuymethodrecord_id,
In fact, it should be the name of the fixedassetpart attribute plus _ id, that isAssetbuymethod_ Id
Therefore, the Migration. CS table creation should be:
Schemabuilder. createtable ( Typeof (Fixedassetpartrecord). Name, T => T. contentpartrecord (). Column < String > ( " Assetcode " ). Column <String > ( " Assetname " ). Column < String > ( " Brand " ). Column < Decimal > ( " Assetvalue " ). Column < Int > ( " Assetbuymethod_id " ));
It took me three days to find the reason for such a small detail.