January 2010 Blog Posts
Wednesday, January 27, 2010 4:45 PM | Comments

Unable to update the EntitySet 'PlanPriceHistory' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. While I was getting my feet wet in Entity Framework 4 (from the Visual Studio 2010 Beta 2 release), I generated my EDMX from an existing legacy database. All was going well – for a few days in fact, until I attempted to Insert an entity to a specific table (seen below). After some digging around in my model/EDMX configuration thinking something was wrong in there, I decided to open the actual table definition for the EntitySet (‘PlanPriceHistory’) that EF was complaining about. The problem with this particular table is that it logically uses a composite primary key (but was mistakenly not defined as such in the database). The fix was as simple as highlighting the columns and...

Friday, January 22, 2010 3:53 PM | Comments

Unit testing a method that relies on DateTime.Now is generally a challenge. Take the below example, which was the first version of a method to get the Current Price of a Product. The business rule for GetCurrentPrice() is simple: find the most recent price where the effective date is not in the future. For this scenario, imagine the user sets the Price of a product to $25,000 but that price doesn't take effect until the next year. Until that time, we must make sure that the system returns the previous (existing) price. The poorly testable method public decimal GetCurrentPrice() { var priceHistory = PriceHistories .Where(ph.EffectiveDate.Date <= DateTime.Now.Date) .OrderByDescending(ph => ph.EffectiveDate) .Take(1) .SingleOrDefault(); return (priceHistory != null) ? priceHistory.Price...

Thursday, January 21, 2010 2:28 PM | Comments

Researching strategies for unit testing view model mappers… It never occurred to try google.com to find that information…