Thursday, February 14, 2013
AntiPatterns
Tuesday, February 12, 2013
LINQ GroupBy Count
class Program
{
static void Main(string[] args)
{
var employeeProducts = new List<EmployeeProduct>();
employeeProducts.Add(new EmployeeProduct(1, 2, "XYZ"));
employeeProducts.Add(new EmployeeProduct(1, 5, "ZXY"));
employeeProducts.Add(new EmployeeProduct(2, 2, "XYZ"));
var way1 = employeeProducts.Select(
ep => new ProductCount
{
ProductNumber = ep.ProductID,
EmployeeNumber = ep.EmployeeID,
CountProducts = employeeProducts.Count(epc => epc.ProductID == ep.ProductID)
});
var way2 = employeeProducts
.GroupBy(ep => ep.ProductID)
.SelectMany(epg => epg.Select(
ep => new ProductCount
{
ProductNumber = ep.ProductID,
EmployeeNumber = ep.EmployeeID,
CountProducts = epg.Count()
}));
}
public class EmployeeProduct
{
public EmployeeProduct(int employeeID, int productID, string name)
{
EmployeeID = employeeID;
ProductID = productID;
Name = name;
}
public int EmployeeID { get; set; }
public int ProductID { get; set; }
public string Name { get; set; }
}
public class ProductCount
{
public int ProductNumber { get; set; }
public int EmployeeNumber { get; set; }
public int CountProducts { get; set; }
}
}
Types of WCF concurrency
- Increase throughput: Many times you want to increase the amount of work your WCF service instance does at any moment of time. In other words, you would like to increase the throughput. Throughput means how much work a given thing can do. By default, a WCF service handles only one request at a given moment of time.
- Integration with a legacy system: Many times your WCF services interact with legacy systems like VB6, COM, etc. It’s very much possible that these systems are not multithreaded, in other words they handle only one request at any given time. So even though your WCF service has concurrent capabilities, you would still like to handle one request at a time. This is achieved by using throttling in combination with WCF concurrency capabilities.



