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

  • SEARCH
  • Home
  • 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 272875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:22:10+00:00 2026-05-12T00:22:10+00:00

I need to build a class in this form namespace BestCompanyEver { public class

  • 0

I need to build a class in this form

namespace BestCompanyEver
{
    public class PersonInfo
    {
        public string Name{get;set;}
        public int Age{get;set;}
    }
}

From a table Person that has columns Name and Age.

Are there any ready to use solutions for this?

I know I can implement this with T4 or Codesmith, but there should be somebody who already did it.

  • 1 1 Answer
  • 1 View
  • 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-12T00:22:11+00:00Added an answer on May 12, 2026 at 12:22 am

    I found some nice T4 template I could use. Its from a project on codeplex.

    LINQ to SQL templates for T4

    The template is hard to read an it took me a while to simplify it.
    Before you can use it you have to download an include (CSharpDataClasses.tt ) from the project.

    Here is my template ():

            <# // L2ST4 - LINQ to SQL templates for T4 v0.82 - http://www.codeplex.com/l2st4
            // Copyright (c) Microsoft Corporation.  All rights reserved.
            // This source code is made available under the terms of the Microsoft Public License (MS-PL)
            #><#@ template language="C#v3.5" hostspecific="True"
            #><#@ include file="L2ST4.ttinclude"
            #><#@ output extension=".generated.cs"
            #><# // Set options here
            var options = new {
                DbmlFileName = Host.TemplateFile.Replace(".tt",".dbml"), // Which DBML file to operate on (same filename as template)
                SerializeDataContractSP1 = false, // Emit SP1 DataContract serializer attributes
                FilePerEntity = true, // Put each class into a separate file
                StoredProcedureConcurrency = false, // Table updates via an SP require @@rowcount to be returned to enable concurrency
                EntityFilePath = Path.GetDirectoryName(Host.TemplateFile) // Where to put the files 
            };
            var code = new CSharpCodeLanguage();
            var data = new Data(options.DbmlFileName);
            var manager = new Manager(Host, GenerationEnvironment, true) { OutputPath = options.EntityFilePath };
            data.ContextNamespace = (new string[] { manager.GetCustomToolNamespace(data.DbmlFileName), data.SpecifiedContextNamespace, manager.DefaultProjectNamespace }).FirstOrDefault(s => !String.IsNullOrEmpty(s));
            data.EntityNamespace = (new string[] { manager.GetCustomToolNamespace(data.DbmlFileName), data.SpecifiedEntityNamespace, manager.DefaultProjectNamespace }).FirstOrDefault(s => !String.IsNullOrEmpty(s));
            manager.StartHeader();
    
            manager.EndHeader();
            var tableOperations = new List<TableOperation>();
                foreach(var table in data.Tables)
                    tableOperations.AddRange(table.Operations);
                foreach(Table table in data.Tables)
                    foreach(OperationType operationType in Enum.GetValues(typeof(OperationType)))
                        if (!tableOperations.Any(o => (o.Table == table) && (o.Type == operationType))) {}
            if (!String.IsNullOrEmpty(data.ContextNamespace)) {}
            foreach(Table table in data.Tables) {
                foreach(TableClass class1 in table.Classes) {
                    manager.StartBlock(Path.ChangeExtension(class1.Name + "Info" ,".cs"));
                    if (!String.IsNullOrEmpty(data.EntityNamespace)) {#>
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            namespace <#=data.EntityNamespace#>
            {   
            <#      }
    
            #>  <#=code.Format(class1.TypeAttributes)#> class <#=class1.Name#>Info
                {
    
            <#      int dataMemberIndex = 1;
                    if (class1.Columns.Count > 0) {
            #><#            foreach(Column column in class1.Columns) {#>
                    private <#=code.Format(column.StorageType)#> <#= "_" + char.ToLower(column.Member[0]) +  column.Member.Substring(1) #><# if (column.IsReadOnly) {#> = default(<#=code.Format(column.StorageType)#>)<#}#>;
    
                    <#=code.Format(column.MemberAttributes)#><#=code.Format(column.Type)#> <#=column.Member#>
                    {
                        get { return <#= "_" + char.ToLower(column.Member[0]) +  column.Member.Substring(1) #>; }
                        set {<#= "_" + char.ToLower(column.Member[0]) +  column.Member.Substring(1) #> = value;}
                    }
    
            <#          }
                    }
            #>
                }
            }
            <#      
                    manager.EndBlock();
                }
            }
            manager.StartFooter();
            manager.EndFooter(); 
            manager.Process(options.FilePerEntity);#>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to build a class that will represent a row in some table
This I'm trying for transfer my current Apache/Modperl site to Starman, and need build
I need to build app with user messages (dialogs). I've solved this problem by
I need to build some client side code which follows this use case: An
I am looking for a form class that: Is standalone/doesnt need a framework to
I need to build a PHP photo processing class, I know there are MANY
Preface: I'm not sure what resources are. I need this form (which is working
I need to build a cron expression based on user input from a form.
I need to build a dynamic form from database. I have following Entity to
I need to build a feature like most of the banks use. Where.. if

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.