LINQ-to-SQL ; , db.GetTable
. ITable
, ITable
. , ...
ITable
, Type
, () Assembly.GetType
:
using (var ctx = new MyDataContext()) {
string name = "Customer";
Type ctxType = ctx.GetType();
Type type = ctxType.Assembly.GetType(
ctxType.Namespace + "." + name);
ITable table = ctx.GetTable(type);
foreach(var row in table) {
Console.WriteLine(row);
}
}
, Type
, Activator
:
object newObj = Activator.CreateInstance(type);
// TODO: set properties (with reflection?)
table.InsertOnSubmit(newObj);
, :
using (var ctx = new MyDataContext()) {
string name = "Customers";
ITable table = (ITable) ctx.GetType()
.GetProperty(name).GetValue(ctx, null);
foreach (var row in table) {
Console.WriteLine(row);
}
}
(Where
) .. , Expression
. , , ...