Recently I gave a talk on Automapper in Ottawa .Net Community, so I though I would post the main ideas of the presentation here also. The demo was based on an Order System where there were just 3 tables/classes, “Order”, “Customer” and “OrderItems” From the diagram we can see that a Customer has a Bio […]
Operator ‘==’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair‘ and ‘‘
You are here beacause you probably got a Linq error, specifically Operator ‘==’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair‘ and ‘‘ So if you wish to do something like this to KeyValuePair using Linq
|
1 2 3 4 5 6 |
var item = myDictionary.FirstOrDefault(x => x.Key == 123); if(item != null) { //blah blah } |
You will get this error Operator ‘!=’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair‘ and ‘‘ Since […]
So sometimes you will get these strange errors or exceptions when using Linq Sequence contains no matching element For example if you use
|
1 |
var result = myEnumerableCollection.First(x => x.Name == person.Name); |
This will throw InvalidOperationException with Sequence contains no matching element. But if you use
|
1 2 3 |
var result = myEnumerableCollection.FirstOrDefault(x => x.Name == person.Name); if(result == null) //did not find in the collection something went wrong or ..... |
Which will return you a null if its not found then you can check if the […]
There are tones of blog post out there on how to redirect http to https. As in when a user request for http://myserver.com/Login.aspx they will be redirected to https://myserver.com/Login.aspx One can do it with IIS but I find that way a bit ugly since you have to create another site and set the 403 to […]
Null Pattern Last time I blogged about “Learn the Null Pattern“, but I forgot to mention one thing about the Null Pattern. That is you have to be mindful of it. For example
|
1 2 3 4 5 6 |
foreach(var id in IDList) { var employee = db.GetEmployee(id); salary = db.CalculateSalary(id); employee.Pay(salary); } |
The code looks okay but what if the GetEmployee method actually returns a NullEmployee? Well that would still be okay, since […]

