LINQ inner query example

//var innerQuery = from depts in this.DbContext.Departments where depts.DeptName == “IT” select depts.DeptId;
            var innerQuery = from depts in this.DbContext.Departments where depts.DeptName == “HR” select depts.DeptId;
            var result = from emp in this.DbContext.Employees where innerQuery.Contains(emp.DeptId) select emp;
            //return employees;
            return result.ToList();

Button type “button” vs. “submit”

The type of the button. Possible values are:

  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element’s events, which are triggered when the events occur.



debug web service project in same solution as web site project

In your solution file, click properties go to the Startup project node (if it is not already selected)

Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have “Start” selected.

Now when you debug your website and put a break point in you webservice it should hit the break point.

Thats all i can think of for your problem. Hope it helps.



How to initialize IEnumerable that be empty and allow to Concat to it?

It seams all you want to do is filter your context.Books by some criteria.

IEnumerable<Book> books = context.Books.Where(b => someConditions);

If you still need the empty IEnumerable you can just call Enumerable.Empty():

IEnumerable<Book> books = Enumerable.Empty<Book>();



Web API error: The ‘ObjectContent`1’ type failed to serialize the response body for content type ‘application/xml

Add following liners in dbcontext constructor

public DbContext() // dbcontext constructor
            : base("name=ConnectionStringNameFromWebConfig")
     this.Configuration.LazyLoadingEnabled = false;
     this.Configuration.ProxyCreationEnabled = false;

Another change has to do for App_Start / WebApiConfig.cs class in my MVC Web API project

var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;



jquery detect textbox value change NOT based on user input

var $myText = $(“#myText”); $“value”, $myText.val()); setInterval(function() { var data = $“value”), val = $myText.val(); if (data !== val) { $“value”, val); alert(“changed”); } }, 100);