/// <summary> /// Load a property values for an entity loaded by the current element of BindingSource loaded with a DataTable /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="M"></typeparam> /// <param name="dataRepository"></param> /// <param name="bindingSource"></param> /// <param name="fieldNames"></param> /// <returns></returns> public static IDictionary <string, object> LoadPropertyValuesFromCurrentBindingSource <T, M>(GenericDataRepository <T, M> dataRepository, BindingSource bindingSource, string[] fieldNames) where T : class where M : class { IDictionary <string, object> ret = null; if (bindingSource.Current != null) { object[] keyvalues = new object[] { }; foreach (string fieldName in fieldNames) { //find the key value from a field object fieldId = (((DataRowView)bindingSource.Current).Row).Field <object>(fieldName); keyvalues = keyvalues.Concat(new object[] { fieldId }).ToArray(); } //find the repository item T item = dataRepository.Find(keyvalues); if (item != null) { //get property values ret = dataRepository.Helper.GetPropertyValues(item); } } return(ret); }
/// <summary> /// Load an entity from the current element of BindingSource loaded with a DataTable /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="M"></typeparam> /// <param name="dataRepository"></param> /// <param name="selectedKeys"></param> /// <returns></returns> public static object[] LoadEntitiesFromSelectedKeys <T, M>(GenericDataRepository <T, M> dataRepository, IList <object[]> selectedKeys) where T : class where M : class { object[] ret = new object[] { }; foreach (object[] selectedKey in selectedKeys) { object found = dataRepository.Find(selectedKey); ret = ret.Concat(new object[] { found }).ToArray(); } return(ret); }
/// <summary> /// Load an entity from the current element of BindingSource loaded with a DataTable /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="M"></typeparam> /// <param name="dataRepository"></param> /// <param name="bindingSource"></param> /// <param name="fieldNames"></param> /// <returns></returns> public static object LoadEntityFromCurrentBindingSource <T, M>(GenericDataRepository <T, M> dataRepository, BindingSource bindingSource, string[] fieldNames) where T : class where M : class { object ret = null; if (bindingSource.Current != null) { object[] keyvalues = new object[] { }; foreach (string fieldName in fieldNames) { //find the key value from a field object fieldId = (((DataRowView)bindingSource.Current).Row).Field <object>(fieldName); keyvalues = keyvalues.Concat(new object[] { fieldId }).ToArray(); } //find the repository item ret = dataRepository.Find(keyvalues); } return(ret); }
public T Find(Expression <Func <T, bool> > expresion) { return(_repository.Find(expresion)); }