2011-11-03 44 views
0

变量假设我已经有出货的类型,我需要在变量找到:获取列名的值时,列名是使用EF4

var categoryLand = ciudad.CategoriaTierra; //string: "A" 
var categoryAir = ciudad.CategoriaAvion; //string "G" 

而且我也有ShippingProducto的具体实例对象我想用:

EFShippingProductoRepository productRepository = new EFShippingProductoRepository(); 
int convProductId = Convert.ToInt32(productId); 
var product = productRepository.FindProductById(convProductId); 

我怎样才能找到名为categoryLand列中的数值?例如,如果在上面的代码中,categoryLand的值为“C”,则需要查找列C内部的值。

有什么建议吗?

enter image description here

回答

1

你可以通过反射属性值:

object value = product.GetType().GetProperty(categoryLand).GetValue(product, 

NULL);