Solved

Get Mappings for a Given Table

Posted on 2014-04-29
3
176 Views
Last Modified: 2014-04-30
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 ?
0
Comment
Question by:Dodsworth
  • 2
3 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40031201
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
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 40031353
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 ?
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40032185
public sub GetTable(TableName as string)
'code

MetaTable t = model.GetTables().Where(Function(tbl) tbl.Name == TableName).SingleOrDefault()

if t isNot Nothing then
  'do something
end if
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question