Frage

I have a simple custom module I am building but I have run into a problem when using the DAL2 GetById.

Here is the POCO declaration of the table i am using:

<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 

I am attempting to delete a record from the database using the following (i removed other methods for clarity):

In the module view:

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

Here is my product controller:

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

PROBLEM:

When the code gets to the following line in the GetITem function

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

The following error is generated:

Value cannot be null. Parameter name: source

Here is a little more detail from the stack trace:

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

QUESTION

Can someone help me figure out why this linq error is being generated, the values being passed to the function are valid and the other repository function like GetItems work properly when supplied with a portalID as their scope.

War es hilfreich?

Lösung

In your model class, you defined the ProductId As Int64, but in your controller methods it is passed as an Integer or Int32. You would think this wouldn't matter, but I have experience other issues where PetaPoco requires very specific implementation in order to work properly. Perhaps this is an issue?

Andere Tipps

At first glance, it looks like the query is bringing back multiple records. Could there be more than one product row with that ID?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top