Общий Редактировать в хранилище - PullRequest
1 голос
/ 13 октября 2010
public T Update(T update) { }

В настоящее время для этого метода я реализую его следующим образом ... Есть ли другой простой способ обойти Linux в Linq

public T Update (T update)
{
    var table = (IEnumerable<T>)(_table.AsQueryable());
    var store = (T)((from a in table.Where(
        a => a.GetType().GetPrimaryKey() == 
            update.GetType().GetPrimaryKey()) select a).Single());
    PropertyInfo[] properties = store.GetType().GetProperties();
    foreach (PropertyInfo property in properties)
    {
        Object propertyValue = null;
        if (null != property.GetSetMethod())
        {
            PropertyInfo entityProperty =
                update.GetType().GetProperty(property.Name);
            if (entityProperty.PropertyType.BaseType ==
                Type.GetType("System.ValueType") ||
                entityProperty.PropertyType ==
                    Type.GetType("System.String"))
                propertyValue =
                    update.GetType().GetProperty(property.Name).GetValue(update, null);
                    if (null != propertyValue)
                        property.SetValue(store, propertyValue, null);
        }
    }
    _context.submitChanges
    return update   
}  

Это работает нормально, однако я надеялся, что смогу улучшитьэтот код, пожалуйста ...

_table является ITable

...