none
Update RRS feed

  • Question

  • hi
    i have some code like this

    Function GetTypeFromTableName(ByVal _TableName As String, ByVal _DataContext As DataContext)

                Dim Mytype As Type = (From t In _DataContext.Mapping.GetTables Where t.TableName = "dbo." + _TableName Select t.RowType.Type).SingleOrDefault
                Return Mytype

        End Function

     Dim DBA As New LINQDataContext
    _TBLName="City"
     TableType = GetTypeFromTableName(_TBLName, DBA)

                    CallByName(obj, "Code", CallType.Set,1)

                    Dim Equery = From T In DBA.GetTable(TableType) Select T

                    Equery = Equery.Where(Function(Oj1) Oj1 Is obj)

                    Dim oopp = From t In Equery Select  CallByName(t, "CName", CallType.Get, Nothing)
                    oopp.ToList.Item(0) = Txt_Name.Text
                    DBA.SubmitChanges()

    submitchange do not work.what is wrong?
    Saturday, January 31, 2009 8:30 PM

All replies

  • You did not actually retrieve any entities from the database. You retrieved a list of strings, and then you overwrote one of the elements in the list with a new value. LINQ to SQL does change tracking for you, but only for full blown mapped entity objects.

    I'm not even sure if the query did work at all, since everything is dynamic at runtime in your example.  I'm not sure how the call to EQuery.Where actually succeeded since Equery has no known static type (other than object) at compile time.  Still, assuming that it somehow works then you should be able to update the name like this:

    Dim entity = DBA.GetTable(TableTypez).Single(Function(Oj1) Oj1 Is obj)

    CallByName(entity, "CName", CallType.Set, Txt_Name.Text)

    DBA.SubmitChanges()

    Wayward LINQ Lacky
    Sunday, February 1, 2009 4:14 AM
    Moderator