R – SubSonic3 VB.Net Add,Update, FirstOrDefault Problems

activerecordsubsonic3vb.net

I hade build sctive record dal with subsonic3 Vb.net templates. and i am dealing with alot of bugs in the sub sonic dlls.

1)in Add() function: (i have fix)
when indx has counter in the db the returnd new key type is decimal the active record fil have an exception "Public member 'Change Type To' n type 'Decimal' not found".
i managed to fix this bug. i changed in the activeRecord template the sub

OlD

    Public Sub SetKeyValue(value As Object) Implements IActiveRecord.SetKeyValue
        If value IsNot Nothing AndAlso value IsNot DBNull.Value Then
            Dim settable = value.ChangeTypeTo(Of <#=tbl.PK.SysType#>)()
            Me.GetType.GetProperty(Me.KeyName()).SetValue(Me, settable, Nothing)
        End If
    End Sub

NEW

   Public Sub SetKeyValue(value As Object) Implements IActiveRecord.SetKeyValue
        If value IsNot Nothing AndAlso value IsNot DBNull.Value Then
            Dim settable = CType( value, <#=tbl.PK.SysType#>)
            Me.GetType.GetProperty(Me.KeyName()).SetValue(Me, settable, Nothing)
        End If
    End Sub 

2)in Update function() function:(I Have Fixed)
the update never do the work . after debuging it apeard that the sql statment of the update never have the "SET" dection of the query its always Like:
UPDATE [tableName] WHERE …
It seems there is a problem in the Subsonic.Repository dll — > IRepository The
Dirty Colums not apdated in new object for example :

  1. Dim Cat as db.Category
  2. Cat.Indx=1
  3. Cat.SetIsNew(False)
  4. Cat.Name= 'Motors'
  5. Cat.Update

Why when update there is no DirtyColumns How can i set Column as Dirty?

–Update problem resolved its not a bug.–
Resolved by adding after line 3 : CAT.SetIsLoaded(True) .
So when the propety IsLoaded is set to tru any column updated will be added to DirtyColums and thes will be Updated To DB

3) the FirstOrDefault Function : (Couldn't fix)
always i meaaaaaaaaan always throw exsiption = "Line 1: Incorrect syntax near '('."
from the SubSonic.Linq dll

Pleeeeeeeeeeeease help

Thanks In advance,
TheGodfather

Best Answer

Firtly, which version of SubSonic3 are you using?

1) Not sure what you are trying to do here.

2) That is not how you update a record, try this...

Dim cat = Category.SingleOrDefault(Function(item) item.CategoryID = 1)
cat.CategoryName = "MOTORS"
cat.Update()

3) Subsonic uses SingleOrDefault() as example above demonstrates.

Related Topic