Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

LINQ Query with Optional search Parameters

LINQ Query with Optional search Parameters:

If you are trying to create a search page to retrieve multiple entities for a given type. For example you have some search criteria fields that can be optionally populated.

As a User I want retrieve company employee data in web portal using following parameters

LINQ Optional Parameters

UserName, Email,City,Department,Designation etc.

LINQ Query with multiple search Parameters:

   System.Collections.Generic.IEnumerable<EmployeeDeails> FilteredUsers;
            if (userData != null )
                FilteredUsers = from U in userData
                                       where ((!string.IsNullOrEmpty(txtUserName.Text) && txtUserName.Text != "0") ? U.Users.UserName == txtUserName.Text : true)
                                       && ((!string.IsNullOrEmpty(txtEmail.Text)) ? ? U.Users.Email == txtEmail.Text : true)
                                       &&                                        ((ddlCity.SelectedValue != "0") ? U. Users.City== Convert.ToInt32(ddlCity.SelectedValue) : true)
                                       ((ddlDepartment.SelectedValue != "0") ? U. Users.Department== Convert.ToInt32(ddlDepartment.SelectedValue) : true)
                                       && ((ddlDesignation.SelectedValue != "0") ? U. Users.Designation == Convert.ToInt32(ddlDesignation.SelectedValue) : true)
                                       select U;


What is Passport authentication and Anonymous access in

Passport authentication: - 

Passport authentication is based on the passport website provided By the Microsoft .So when user logins with credentials it will be reached to the passport website ( i.e. gmail,hotmail ,windows live etc) where authentication will happen. If Authentication is successful it will return a token to your website.

Anonymous access: - If you do not want any kind of authentication then you will go for Anonymous access.

Web.config sample settings:

            <allow  users="?"/>