SoDCDataContext dc = new SoDCDataContext();
var persons = (dc.usp_Persons(personId, firstName, lastName, site)).ToList();
But it is better to see all our logic in the PersonBL class (here really all our business logic has to be!) and use stored procedure in, may be, very special and complicated cases. So, we just change our stored procedure to some LINQ code. Suppose, we use some special class to see persons selected data:
public class C_PersonDGV
{
public short PersonNum { get; set; }
public string PersonID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Telephon { get; set; }
public string Note { get; set; }
public short? SiteHome { get; set; }
public string SiteName { get; set; }
public DateTime? LastUpdate { get; set; }
}
Our DataObjectMethod of the PersonBL class (in SoBL project) will look so:
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static List<C_PersonDGV> FindPersonsDGV(
string personId, string firstName,
string lastName, short site)
{
SoDCDataContext dc = new SoDCDataContext();
IEnumerable<C_PersonDGV> personsDGV =
from p in dc.C_Persons
where
p.PersonID.Equals((personId.Equals("-999")) ?
p.PersonID : personId)
&&
p.FirstName.Equals((firstName.Equals("-999")) ?
p.FirstName : firstName)
&&
p.LastName.Equals((lastName.Equals("-999")) ?
p.LastName : lastName)
&&
p.SiteHome.Equals(site == -999 ?
p.SiteHome : site)
select new C_PersonDGV
{
PersonNum = p.PersonNum,
PersonID = p.PersonID,
FirstName = p.FirstName,
LastName = p.LastName,
Email = p.Email,
Telephon = p.Telephone,
Note = p.Note,
SiteHome = p.SiteHome,
SiteName = p.NC_Site.SiteName,
LastUpdate = p.LastUpdate
};
return personsDGV.ToList();
}