Here we have two class customer and sales, if we need a common method for converting data table into a list of any type we can use refection.
public
class
Customer
{
public string
Name{set;get;}
public string
Address{set;get}
}
public class
Sales
{
public string
Product{set;get;}
public int
Quantity{set;get}
}
Problem is that when the name of properties and column is diffrent what we do?
in that case we can use a custome atribute that allows us to keep declarative
information ie column name
so our custome atribute is like this
public
class
DataTableColName :
Attribute
{
string coulumnName =
string.Empty;
public string
CoulumnName
{
get { return
coulumnName; }
set { coulumnName =
value; }
}
public DataTableColName(string
colName)
{
coulumnName =
colName;
}
}
Above class will be
public
class
Customer
{
[DataTableColName("CustomerName")]
public string
Name{set;get;}
[DataTableColName("CustomerAddress")]
public string
Address{set;get}
}
public class
Sales
{
[DataTableColName("ProductName")]
public string
Product{set;get;}
[DataTableColName("ProductQty")]
public int
Quantity{set;get}
}
So generic method for converting DataTble is
clementedwinPosted May 4, 2012, 10:20 AM
I'm currently working on a huge public interfacing web site...we are in the process of deciding the Data Access Technology...I personally have a feeling that LINQ 2 SQL & Entity Framework or for smaller or less mission-critical applications where performance is not a major criteria... I'm suggesting the client to use Data Access Application Block with Stored Procedures...with a combination of "Custom Attribute / System.Reflection " to map the physical model to the conceptual model... Any suggestions...