我在这里遵循教程:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-1但我遇到第4部分的问题:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-4有一点需要注意,我正在VB.Net中编写代码。话虽如此,我已经完成了第3部分并且能够创建一个新模块(只需添加一个简单的类库)并让Orchard识别并启用它。但是,在第4部分中,当我创建Migrations,ProductPart和ProductRecord类时,没有任何反应。我没有收到有关模块已更改的通知。
不可否认,我今天之前还没有在VB.net中做过lambdas,这也是我第一次在VB.Net中尝试Auto Properties。但由于没有编译时错误,我假设我正确编写了代码。
这是我的3个文件的代码:
Imports Orchard.ContentManagement.Records
Namespace Orchard.Webshop
Public Class ProductRecord
Inherits ContentPartRecord
Public Overridable Property Price() As Decimal
Public Overridable Property Sku() As String
End Class
End Namespace
Imports Orchard.ContentManagement
Namespace Orchard.Webshop
Public Class ProductPart
Inherits ContentPart(Of ProductRecord)
Public Property Price() As Decimal
Get
Return Record.Price
End Get
Set(value As Decimal)
Record.Price = value
End Set
End Property
Public Property Sku() As String
Get
Return Record.Sku
End Get
Set(value As String)
Record.Sku = value
End Set
End Property
End Class
End Namespace
Imports Orchard.Data.Migration
Imports Orchard.Core.Contents.Extensions
Imports Orchard.ContentManagement.MetaData
Namespace Orchard.Webshop
Public Class Migrations
Inherits DataMigrationImpl
Public Function Create()
SchemaBuilder.CreateTable("ProductRecord", Function(table)
table.ContentPartRecord() _
.Column(Of Decimal)("Price") _
.Column(Of String)("Sku", Function(column)
column.WithLength(50)
End Function)
End Function)
Return 1
End Function
Public Function UpdateFrom1()
ContentDefinitionManager.AlterPartDefinition(GetType(ProductPart).Name, Function(part)
part.Attachable()
End Function)
Return 2
End Function
End Class
End Namespace
答案 0 :(得分:1)
查看Orchard的源代码,以获得快速参考codeplex source browser
Orchard.Data.Migration.DataMigrationManager类对所有注入的IDataMigration类使用反射,并调用以下方法
/// <summary>
/// Returns the Create method from a data migration class if it's found
/// </summary>
private static MethodInfo GetCreateMethod(IDataMigration dataMigration) {
var methodInfo = dataMigration.GetType().GetMethod("Create", BindingFlags.Public | BindingFlags.Instance);
if(methodInfo != null && methodInfo.ReturnType == typeof(int)) {
return methodInfo;
}
return null;
}
您的VB函数似乎没有ReturnType,所以我相信当您编写方法时它应该可以正常工作
Public Function Create() As Integer
// do stuff
Return 1;
End Function
Public Function UpdateFrom1() As Integer
// do stuff
Return 2;
End Function