Finding Stored Procedures that Accesses Particular Table or Column in SQL Server | SQL Server Tutorial

By querying the Procedures table in Sys as given below, we can find the SQL Server stored procedures that refers particular column are tables.

FROM sys.procedures

The result will be the list of SQL Server stored procedure names that refers to particular table or column.

Deleting Multiple Records in Entity Framework | Entity Framework Tutorial

Sometimes you may need to delete multiple records. In such case, developers use to iterate through the collection using foreach and will set each entity state to modified. Some developers use to write an extension method as below to handle deleting multiple records in entity framework.

Extension Method:

public static void DeleteObjects(this ObjectSet set, Expression> predicate) where T : EntityObject { foreach (var entity in set.AsQueryable().Where(predicate)) set.DeleteObject(entity); }

Usage of Extension Method

db.Employees.DeleteObjects(x => x.Country == "India");

However to make the life of the .Net developer easier, entity framework 6 has introduced a method named RemoveRange to delete multiple records at one shot as given in the below code snippet:

db.People.RemoveRange(db.Employees.Where(x => Country == "India"));

How to Get Browser Agent from ASP.NET Web API Controller? | ASP.NET Web API Tutorial

The easiest way to get the full user-agent from inside an ASP.NET Web API-controller is as given below:
var userAgent = Request.Headers.UserAgent.ToString();
It gives exactly the same result as doing the manual step like this:
// var headers = request.Headers.GetValues("User-Agent");
// var userAgent = string.Join(" ", headers);

Excluding Required Property from ModelState.IsValid | ASP.NET MVC Tutorial

You can exclude any property from validating using parameter binding. Set the exclude property in Bind attribute of a parameter as [Bind(Exclude = "Password")] 

In this way, by add exclusions to your action and explicitly state what can and can't be binded we can achieve in ASP.NET MVC

public class Person 
    public int id { get; set; } 

    public string FirstName { get; set; } 

    public string LastName { get; set; } 
FirstName And LastName are Requerd. I want to exclude LastName from validating:

public ActionResult Edit([Bind(Exclude = "LastName")]Person person)
    //your code for ModalState validation;    

Process Flow of Single and Multitenancy ASP.NET MVC Application | ASP.NET MVC Tutorial

Single-Tenancy Application
The steps that lead from a user entering a website address in his browser to viewing the content are fairly straightforward. The browser sends a request for the content at that address to a server. The server receives the request, matches the address with an application, and passes the request on to that application for processing. The application reads the request, creates a response, and passes the response back to the server. The server returns the response to the browser and the browser presents the response content to the user. This is sometimes referred to as a single tenant application architecture. Each client application is matched with a single IP address and host name so that, as requests come in, the server can route them to the appropriate application (Figure 1).

Simplifying AccountController by Removing External Login Related Actions | ASP.NET MVC Tutorial

There are a number of methods on AccountController related to External Logins. If you examine AccountController carefully, you can go through and delete the code for the following actions:
  • Dissociate()
  • ExternalLogin()
  • ExternalLoginCallback()
  • LinkLogin()
  • LinkLoginCallback()
  • ExternalLoginConfirmation()
  • ExternalLoginFailure()
  • RemoveAccountList()
Additionally, there is a code #region for helpers. From here, we can delete the following items:
  • The member constant XsrfKey
  • The entire class ChallengeResult
At this point, we can also right-click in the code file and select Remove and Sort Usings to clear out unused namespaces

Delete External Login Related Views:
Along with the unnecessary Controller methods we just removed, we can also remove the unnecessary views related to external logins. If we open the Views => Account folder in Solution Explorer, we find we can delete the highlighted views below from our project:

ng-model Doesn't Work Inside ng-if | Scope Properties Doesn't Change inside ng-if | AngularJS Tutorial

If an ng-model is used inside an ng-if, then the model does not work as expected.

<div ng-app >
    <div ng-controller="main">

        Test A: {{testa}}<br />
        Test B: {{testb}}<br />
        Test C: {{testc}}<br />

            testa (without ng-if): <input type="checkbox" ng-model="testa" />
        <div ng-if="!testa">
            testb (with ng-if): <input type="checkbox" ng-model="testb" />
        <div ng-if="!someothervar">
            testc (with ng-if): <input type="checkbox" ng-model="testc" />

The ng-if directive will create a child scope. So the CheckBox changes the testb inside of the child scope and not the outer parent scope.

To modify the data in the parent scope, you'll need to make use of $parent as given below:

You can use $parent to refer to the model defined in the parent scope like this
<input type="checkbox" ng-model="$parent.testb" />

How to Convert Synchronous ASP.NET MVC Action to Asynchronous ASP.NET MVC Action | Asynchronous Support in ASP.NET MVC Controller | ASP.NET MVC Tutorial

In ASP.NET MVC controller action method receives data from a web request and passes the data to a view which then creates the HTML to be sent to the browser. Frequently the action method needs to get data from a database or web service in order to display it in a web page or to save data entered in a web page. In those scenarios it's easy to make the action method asynchronous: instead of returning an ActionResult object, you return Task<ActionResult> and mark the method with the async keyword. Inside the method, when a line of code kicks off an operation that involves wait time, you mark it with the await keyword.
Here is a simple action method that calls a repository method for a database query:
public ActionResult Index()
    string currentUser = User.Identity.Name;
    var result = fixItRepository.FindOpenTasksByOwner(currentUser);

    return View(result);
And here is the same method that handles the database call asynchronously:
public async Task<ActionResult> Index()
    string currentUser = User.Identity.Name;
    var result = await fixItRepository.FindOpenTasksByOwnerAsync(currentUser);

    return View(result);
Under the covers the compiler generates the appropriate asynchronous code. When the application makes the call toFindTaskByIdAsync, ASP.NET makes the FindTask request and then unwinds the worker thread and makes it available to process another request. When the FindTask request is done, a thread is restarted to continue processing the code that comes after that call. During the interim between when the FindTask request is initiated and when the data is returned, you have a thread available to do useful work which otherwise would be tied up waiting for the response.