1

作成中の単純なカスタム モジュールがありますが、DAL2 GetById の使用時に問題が発生しました。

私が使用しているテーブルのPOCO宣言は次のとおりです。

<TableName("KrisisStore_Products")> _    
<PrimaryKey("ProductId", AutoIncrement:=True)> _
<Cacheable("Products", CacheItemPriority.Default, 20)> _
<Scope("PortalId")>
Public Class Product

    Public Property ProductId As Int64
    Public Property PortalId As Integer
    Public Property ModuleId As Integer
    ''other columns here

End Class 

次を使用してデータベースからレコードを削除しようとしています(明確にするために他の方法を削除しました):

モジュール ビューで:

  Dim pc As New ProductController
  pc.DeleteItem(e.CommandArgument, PortalId)

ここに私の製品コントローラーがあります:

Imports System.Collections.Generic
Imports DotNetNuke.Data

Namespace Components

    Public Class ProductController

        Public Sub DeleteItem(ByVal itemId As Integer, ByVal PortalId As Integer)
            Dim _item As Product = GetItem(itemId, PortalId)
            DeleteItem(_item)
        End Sub

        Public Sub DeleteItem(ByVal p As Product)
            Using ctx As IDataContext = DataContext.Instance()
                Dim rep As IRepository(Of Product) = ctx.GetRepository(Of Product)()
                rep.Delete(p)
            End Using
        End Sub

        Public Function GetItem(ByVal itemId As Integer, ByVal PortalId As Integer) As Product
            Dim p As Product

            Using ctx As IDataContext = DataContext.Instance()
                Dim rep As IRepository(Of Product) = ctx.GetRepository(Of Product)()
                p = rep.GetById(Of Int32, Int32)(itemId, PortalId)
            End Using
            Return p
        End Function
    End Class
End Namespace

問題:

コードが GetITem 関数で次の行に到達したとき

p = rep.GetById(Of Int32, Int32)(itemId, PortalId)

次のエラーが生成されます。

値を null にすることはできません。パラメータ名: ソース

スタック トレースの詳細を次に示します。

InnerException: Value cannot be null. Parameter name: source
FileName:
FileLineNumber: 0
FileColumnNumber: 0
Method: System.Linq.Enumerable.SingleOrDefault
StackTrace:
Message: DotNetNuke.Services.Exceptions.ModuleLoadException: Value cannot be null. Parameter name: source ---> System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at DotNetNuke.Data.RepositoryBase`1.GetById[TProperty,TScopeType](TProperty id, TScopeType scopeValue) at Krisis.Modules.KrisisStore.Components.ProductController.GetItem(Int32 itemId, Int32 PortalId) in C:\websites\dnndev.me\DesktopModules\KrisisStore\Components\ProductController.vb:line 51

質問

このlinqエラーが生成されている理由、関数に渡される値が有効であり、スコープとしてportalIDが指定されている場合、GetItemsなどの他のリポジトリ関数が適切に機能する理由を誰かが理解するのを手伝ってくれますか?

4

2 に答える 2

0

一見すると、クエリによって複数のレコードが返されているように見えます。その ID を持つ製品行が複数ある可能性はありますか?

于 2013-12-16T20:32:46.493 に答える