CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: csharp

DataFieldMappingConsoleSample.Program.cs

129 Views   
namespace DataFieldMappingConsoleSample { using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; class Program { static void Main(string[] args) { SqlConnection connection = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=localhost"); SqlCommand command = new SqlCommand("SELECT * FROM sysobjects ORDER by type, name", connection); connection.Open(); IDataReader dr = command.ExecuteReader(); IEnumerable<TableInfo> tables = dr.AsEnumerable<TableInfo>(); tables.All(tableInfo => { Console.WriteLine("Id: {0}, Name: {1}, Type: {2}", tableInfo.Id, tableInfo.Name, tableInfo.Type); return true; }); connection.Close(); Console.WriteLine("Press any key to finish..."); Console.ReadKey(false); } } public class TableInfo { [DataFieldMapping("Id")] public int Id { get; set; } [DataFieldMapping("Name")] public string Name { get; set; } [DataFieldMapping("Type")] public string Type { get; set; } } }
by Luciano Evaristo Guerche (Gorše)
  December 21, 2011 @ 10:20am
Tags:
Add a comment


Report Abuse
brought to you by:
West Wind Techologies