Solved

Get Mappings for a Given Table

Posted on 2014-04-29
3
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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