I’m making this method retrieve records from the Data Base. As you can see I want to return a List<ITieneID> where ITieneID is an Interface defined on my business layer.
AtlasWFM_Entities.Clases.Area implements that interface. It is pretty clear that this is not a good way to accomplishing it. Here’s the code:
public override List<ITieneID> Buscar(ITieneID elementoPatron)
{
List<ITieneID> result = new List<ITieneID>();
var resultado = from a in base.Repository.Context.Areas
where a.areaID.Equals(elementoPatron.ID) || a.areaDescripcion.Contains(elementoPatron.Descripcion)
select new AtlasWFM_Entities.Clases.Area
{
ID = a.areaID,
Descripcion = a.areaDescripcion,
Estado = a.areaEstado,
};
foreach (var r in resultado)
{
ITieneID t = new AtlasWFM_Entities.Clases.Area
{
ID = r.ID,
Descripcion = r.Descripcion,
Estado = r.Estado,
};
result.Add(t);
}
return result;
}
Any Ideas how to improve this?
UPDATE: That don’t compile, but this should:
In fact, I think you can reduce the whole thing to:
of a little more concise: