Link to home
Start Free TrialLog in
Avatar of Dodsworth
Dodsworth

asked on

Get Mappings for a Given Table

I'm using this snippet of code...

Using dc = New Context(ConnectionString)
                Dim model = New System.Data.Linq.Mapping.AttributeMappingSource().GetModel(GetType(Context))

                For Each mt In model.GetTable()
                    dBug(mt.TableName)
                    For Each dm In mt.RowType.DataMembers
                        dBug(" " + dm.MappedName + " " + dm.Type.ToString)
                    Next
                Next

Open in new window


Is there a way that I can specify the TableName (As String) to return the mappings for a given table ?
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

public sub GetTable(Tablename as string)
Using dc = New Context(ConnectionString)
                Dim model = New System.Data.Linq.Mapping.AttributeMappingSource().GetModel(GetType(Context))

                For Each mt In model.GetTable()
                    if mt.TableName.ToLower = TableName.Tolower
                    dBug(mt.TableName)
                    For Each dm In mt.RowType.DataMembers
                        dBug(" " + dm.MappedName + " " + dm.Type.ToString)
                    Next
                   end if
                Next

end sub
Avatar of Dodsworth
Dodsworth

ASKER

oops the code I posted was mid edit.  It should have read..

For Each mt In model.GetTables()

Open in new window


I was hoping that there would be a way to get the table directly using model.GetTable. But this requires a CLR Row Type.  I don't understand how a row type can return a metatable ?
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial