Click here to Skip to main content
15,175,307 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have 1000 record of collection now i want search data specific field
Posted

1 solution

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 
        }; 

    ////------or lamda---------- 
    //IEnumerable<C_PersonDGV> personsDGV = dc.C_Persons.Where 
    //    ( 
    //        p => 
    //        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(p => 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(); 
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900