B
Bill McCormick
Hello,
I need a way to iterate through an Entity Sets columns by name, then
retrieve the data from each field. Then, I need to map the data into
fields of another object that has field names that are the same as the
DB field names.
Here's what I have so far:
A property of the DataContaxt that returns an Enumerable object of
column names:
public partial class SQLScrpDbDataContext
{
public IEnumerable<string> DspColumnNames {
get {
AttributeMappingSource ams = new AttributeMappingSource();
MetaModel metaModel = ams.GetModel(typeof(SQLScrpDbDataContext));
MetaTable metaTable = metaModel.GetTable(typeof(Dsp));
MetaType metaType = metaTable.RowType;
foreach (MetaDataMember dataMember in metaType.DataMembers) {
if(dataMember.DbType != null)
yield return dataMember.MappedName;
}
}
}
}
So that part works but here's where I'm stuck:
Inside a funtion that will complete the mapping ...
ScOptionalTktFields optionalXML = new ScOptionalTktFields();
I have a Dsp Entity object (DspRec) and I want to map each field to an
identically named field in an another object (optionalXML.) So instead
of having a long list of something that looks like this:
optionalXML.DspId = DspRec.DspId;
... and so on for about 50 fields ...
I could have something like this (making up some syntax to illustrate
what I'd like to achieve):
foreach (string name in this._db.DspColumnNames) {
optionalXML[name] = DspRec[name];
}
I'm using VS2010 Beta1 and .NET4.0 Beta1.
Thanks,
Bill
I need a way to iterate through an Entity Sets columns by name, then
retrieve the data from each field. Then, I need to map the data into
fields of another object that has field names that are the same as the
DB field names.
Here's what I have so far:
A property of the DataContaxt that returns an Enumerable object of
column names:
public partial class SQLScrpDbDataContext
{
public IEnumerable<string> DspColumnNames {
get {
AttributeMappingSource ams = new AttributeMappingSource();
MetaModel metaModel = ams.GetModel(typeof(SQLScrpDbDataContext));
MetaTable metaTable = metaModel.GetTable(typeof(Dsp));
MetaType metaType = metaTable.RowType;
foreach (MetaDataMember dataMember in metaType.DataMembers) {
if(dataMember.DbType != null)
yield return dataMember.MappedName;
}
}
}
}
So that part works but here's where I'm stuck:
Inside a funtion that will complete the mapping ...
ScOptionalTktFields optionalXML = new ScOptionalTktFields();
I have a Dsp Entity object (DspRec) and I want to map each field to an
identically named field in an another object (optionalXML.) So instead
of having a long list of something that looks like this:
optionalXML.DspId = DspRec.DspId;
... and so on for about 50 fields ...
I could have something like this (making up some syntax to illustrate
what I'd like to achieve):
foreach (string name in this._db.DspColumnNames) {
optionalXML[name] = DspRec[name];
}
I'm using VS2010 Beta1 and .NET4.0 Beta1.
Thanks,
Bill