Solved

Get Mappings for a Given Table

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

12 Experts available now in Live!

Get 1:1 Help Now