Solved

Get Mappings for a Given Table

Posted on 2014-04-29
3
172 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 39

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 39

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now