Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I'm trying to implement solution of AutoRefresh Entity Framework Data Using SQL Server Service Broker[^] and for the entire table it is working, unfortunately, when I want to execute stored procedure with parameters using linq I get:

Unable to cast object of type 'WhereSelectEnumerableIterator`2[HP_Timer_Tool_V3.EmployeeMetricResult,System.Nullable`1[System.Decimal]]' to type 'System.Data.Entity.Infrastructure.DbQuery`1[HP_Timer_Tool_V3.EmoloyeeMetric]'.


My code:

VB
Dim allie = (maintimer.EmoloyeeMetric(21385650, "Non-Process", "Process", "Startup", Date.Now, Date.Today))

Productivity = New AutoRefreshWrapper(Of EmoloyeeMetric)(allie.Select(Function(o) o.DayProd), maintimer, RefreshMode.StoreWins)


AutoRefresheWrapper:

VB
Public Class AutoRefreshWrapper(Of T As Class)
    Implements IEnumerable(Of T)
    Implements INotifyRefresh
    Private entitySet As IEnumerable(Of T)
    Private _nullable As Decimal?
    Private _refreshMode As RefreshMode

    Public Sub New(dbq As DbQuery(Of T), dbContext As DbContext, refreshMode As RefreshMode)
        Me.entitySet = dbq
        DirectCast(dbContext, System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext.AutoRefresh(refreshMode, Me)
    End Sub


If there a way to cast this object? When I was trying to materialized it with
FirstOfDefault()
then, exception was:
Value of type 'Decimal?' cannot be converted to 'System.Data.Entity.Infrastructure.DbQuery(Of HP_Timer_Tool_V3.EmoloyeeMetric)'.


Thank you for any suggestions
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900