Results 1 to 2 of 2

Thread: LINQ query returning cast exception

  1. #1
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22

    LINQ query returning cast exception

    I am learning linq, up to this point its been going well but cant figure this one out! Using LINQ to query a sharepoint list, done it 100 times by this point but never had this problem before.

    Specified cast is not valid.SPAuthSnrMgmtChangesWP at Set__wrkflwCreateID(Object , Object ) at Microsoft.SharePoint.Linq.StaticPropertyMap.SetToE ntity(Object entity, Object value) at Microsoft.SharePoint.Linq.SPItemMappingInfo.Materi alizeEntity[TEntity](DataContext dc, SPDataList list, SPListItem item, SPItemMappingInfo itemMappingInfo, JoinPath joinPath) at lambda_method(ExecutionScope , SPListItem ) at System.Linq.Enumerable.<>c__DisplayClass12`3.b__11 (TSource x) at System.Linq.Enumerable.WhereSelectEnumerableIterat or`2.MoveNext() at SPAuthSnrMgmtChangesWP.ActionChangeRequestUserCont rol.gvAuth_RowCommand(Object sender, GridViewCommandEventArgs e)

    [XCODE]
    PrivateSub gvAuth_RowCommand(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvAuth.RowCommand
    Using
    ctx AsSPlistsDataContext = NewSPlistsDataContext(pURL)
    If e.CommandName = "ActionSubmit"Then
    Dim s AsString = CType(e.CommandArgument, String)
    Try
    Dim results = From c In ctx.EAChangeList Where c.ChangeID = s _
    Select c

    ForEach item In results
    item.ChangeApproverDate =
    Date.Today
    item.ChangeApproverApproved =
    "Approved"

    Next

    Catch ex AsException
    lblMsg.Text = lblMsg.Text & ex.Message & ex.Source & vbCr & ex.StackTrace.ToString
    EndTry
    ctx.SubmitChanges()
    EndIf
    EndUsing

    EndSub
    [/XCODE]

    Quick Update:

    It actually seem to be the query itself causing the problem
    Dim results = From c In ctx.EAChangeList Where c.ChangeID = s _
    Select c

    Last edited by Lotok; 02-15-2012 at 6:10 AM. Reason: Update

  2. #2
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    I ended up just using caml.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking