Hi,
I have a scenario where I want to select a single property of one of
my mapped classes. The tricky bit is I want to be able to specify the
property at runtime.
I have sort of worked out how to do it using the method below but the
problem is that I get an exception fairly regularly about the
enumerator being not ready. Has anyone done a similar thing and have a
more robust approach or any suggestions?
public override object GetProperty(Guid id, string propertyName) {
try {
PropertyInfo property = typeof(T).GetProperty(propertyName);
if (property == null) {
throw new ApplicationException("Property " + propertyName + "
for " + typeof(T).Name + " could not be found, GetProperty failed.");
}
else {
using (DataContext dataContext =
DBLinqContext.CreateDBLinqDataContext(m_storageType, m_dbConnStr)) {
Table<T> table = dataContext.GetTable<T>();
string idString = id.ToString();
IEnumerator result = (from asset in table where asset.Id ==
idString select asset).Select("new (" + propertyName +
")").GetEnumerator();
result.MoveNext();
var resultObj = result.Current;
PropertyInfo resultProperty = resultObj.GetType().GetProperty
(propertyName);
return resultProperty.GetValue(resultObj, null);
}
}
}
catch (Exception excp) {
logger.Error("Exception DBLinqAssetPersistor GetProperty (for " +
typeof(T).Name + "). " + excp.Message);
throw;
}
}
Thanks,
Aaron
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---