I have a question! .. The fact is that I have several classes related to entity F. and each class does the same for each object. List, save, modify search ext. How can I do it to simplify it in a single class? Thanks!
I have a question! .. The fact is that I have several classes related to entity F. and each class does the same for each object. List, save, modify search ext. How can I do it to simplify it in a single class? Thanks!
You could have stored procedures in your BD and call them from general classes depending on your object to modify or bring. An example of how it would be
public static List<object> Consultar(object obj, string Procedimiento, string Dato)
{
List<object> objs = new List<object>(); DataTable dt = clsDb.Consultar(Procedimiento, Dato);
Type Tipo = obj.GetType();
PropertyInfo[] propiedades = Tipo.GetProperties(); int Long = propiedades.Length; int Index = 0; int Field = 0;
foreach (DataRow row in dt.Rows)
{
object[] objDato = new object[Long];
Field = 0;
foreach (var prop in propiedades) { objDato[Field] = row[prop.Name].ToString(); Field++; }
objs.Add(objDato);
}
return objs;
}
and an example of a procedure stored in your DB
create procedure [dbo].[spClientesMostrar] ( @Buscar varchar(50) = '' ) as
select * from TClientes where Cliente like '%' + @Buscar + '%' and Anulado = 0 order by Cliente
If I do not wrap this up, it's called 'Reflection', I hope it serves you: D