Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 314767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:13:48+00:00 2026-05-12T08:13:48+00:00

I have a class that add extra information about a column for linq2sql (see

  • 0

I have a class that add extra information about a column for linq2sql (see code below)

right now, I have to explicitly tell what column I want that info on, how would you put that code with a loop on every column in every table from a dbml file?

I was doing my test on a very very small DB, now I have to implement it on a much more bigger database and I really don’t want to do it manually for every tables/columns

it will take hours.

how it’s being used:

Partial Class Contact ''contact is a table inside a dbml file.

Private _ContactIDColumn As ExtraColumnInfo
Private _ContactNameColumn As ExtraColumnInfo
Private _ContactEmailColumn As ExtraColumnInfo
Private _ContactTypeIDColumn As ExtraColumnInfo

Private Sub OnCreated()
    initColumnInfo()
End Sub

Private Sub initColumnInfo()
    Dim prop As PropertyInfo

    prop = Me.GetType.GetProperty("ContactID")
    _ContactIDColumn = New ExtraColumnInfo(DirectCast(prop.GetCustomAttributes(GetType(ColumnAttribute), False)(0), ColumnAttribute))

    prop = Me.GetType.GetProperty("ContactName")
    _ContactNameColumn = New ExtraColumnInfo(DirectCast(prop.GetCustomAttributes(GetType(ColumnAttribute), False)(0), ColumnAttribute))

    prop = Me.GetType.GetProperty("ContactEmail")
    _ContactEmailColumn = New ExtraColumnInfo(DirectCast(prop.GetCustomAttributes(GetType(ColumnAttribute), False)(0), ColumnAttribute))

    prop = Me.GetType.GetProperty("ContactTypeID")
    _ContactTypeIDColumn = New ExtraColumnInfo(DirectCast(prop.GetCustomAttributes(GetType(ColumnAttribute), False)(0), ColumnAttribute))

    prop = Nothing
End Sub

Public ReadOnly Property ContactIDColumn() As ExtraColumnInfo
    Get
        Return _ContactIDColumn
    End Get
End Property

Public ReadOnly Property ContactNameColumn() As ExtraColumnInfo
    Get
        Return _ContactNameColumn
    End Get
End Property

Public ReadOnly Property ContactEmailColumn() As ExtraColumnInfo
    Get
        Return _ContactEmailColumn
    End Get
End Property

Public ReadOnly Property ContactTypeIDColumn() As ExtraColumnInfo
    Get
        Return _ContactTypeIDColumn
    End Get
End Property
End Class

what is ExtraColumnInfo:

Public Class ExtraColumnInfo

Private _column As ColumnAttribute
Private _MaxLength As Nullable(Of Integer)
Private _Precision As Nullable(Of Integer)
Private _Scale As Nullable(Of Integer)
Private _IsIdentity As Boolean
Private _IsUniqueIdentifier As Boolean

Sub New(ByVal column As ColumnAttribute)
    Dim match As Match

    _column = column

    Match = Regex.Match(DBType, "^.*\((\d+)\).*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
    _MaxLength = If(match.Success, Convert.ToInt32(match.Groups(1).Value), Nothing)

    match = Regex.Match(DBType, "^.*\((\d+),(\d+)\).*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
    _Precision = If(Match.Success, Convert.ToInt32(Match.Groups(1).Value), Nothing)

    match = Regex.Match(DBType, "^.*\((\d+),(\d+)\).*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
    _Scale = If(match.Success, Convert.ToInt32(match.Groups(2).Value), Nothing)

    match = Regex.Match(DBType, "^.*\bIDENTITY\b.*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
    _IsIdentity = match.Success

    match = Regex.Match(DBType, "^.*\bUniqueIdentifier\b.*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
    _IsUniqueIdentifier = match.Success
End Sub

'others available information
'AutoSync
'Expression
'IsVersion
'Name
'Storage
'TypeId
'UpdateCheck
'maybe more

Public ReadOnly Property CanBeNull() As Boolean
    Get
        Return _column.CanBeNull
    End Get
End Property

Public ReadOnly Property IsDbGenerated() As Boolean
    Get
        Return _column.IsDbGenerated
    End Get
End Property

Public ReadOnly Property IsPrimaryKey() As Boolean
    Get
        Return _column.IsPrimaryKey
    End Get
End Property

Public ReadOnly Property DBType() As String
    Get
        Return _column.DbType
    End Get
End Property

Public ReadOnly Property MaxLength() As System.Nullable(Of Integer)
    Get
        Return _MaxLength
    End Get
End Property

Public ReadOnly Property Precision() As System.Nullable(Of Integer)
    Get
        Return _Precision
    End Get
End Property

Public ReadOnly Property Scale() As System.Nullable(Of Integer)
    Get
        Return _Scale
    End Get
End Property

Public ReadOnly Property IsIdentity() As Boolean
    Get
        Return _IsIdentity
    End Get
End Property

Public ReadOnly Property IsUniqueIdentifier() As Boolean
    Get
        Return _IsUniqueIdentifier
    End Get
End Property
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:13:48+00:00Added an answer on May 12, 2026 at 8:13 am

    I took the T4 template and modified it a little to automatically put inside the generated class the column information,

    in the import I added

        Imports System.Reflection
        Imports System.Text.RegularExpressions
    

    at line 228, added these line:

        <# foreach(Column column in class1.Columns) {#>
        Private _<#=column.Member#>Column As ExtraColumnInfo
        Public ReadOnly Property <#=column.Member#>Column() As ExtraColumnInfo
            Get
                Return _<#=column.Member#>Column
            End Get
        End Property
    
        <#              }#>
    

    at line 298 I added

        Dim prop As PropertyInfo
        <# foreach(Column column in class1.Columns) {#>
        prop = Me.GetType.GetProperty("<#=column.Member#>")
        _<#=column.Member#>Column = New ExtraColumnInfo(DirectCast(prop.GetCustomAttributes(GetType(ColumnAttribute), False)(0), ColumnAttribute))
        <#      }#>
    

    at the end of the file, I added my own class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer cc -o yourprog yourprog.c -lstatic or cc -o yourprog yourprog.c… May 12, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer No, you can't, but you can pass the :allow_nil =>… May 12, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer For a modern iOS XX version skip the answer as… May 12, 2026 at 8:59 pm

Related Questions

I have an interesting situation and I'm wondering if there is a better way
I'm building a simple game which consists of Mobiles -- the in-game characters (Mobs).
In an application I'm building I had an enumeration of account statuses: public enum
This is a simplification of the issue (there are lots of ways of doing

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.