Tuesday, November 06, 2012

Dynamic Entity Framework Filtering

I recently created a library that works against an Entity Framework (V5) model and allows for creation of a central method which accepts:
  • A generic type parameter indicating which entity type to return.
  • Any number of parameters (int or list of ints indicating ids) which will contain ids of related entities.
The library will return generated code for the linq to EF query which when compiled (by passing it to a compiler helper) will return IQueryable (for further filtering if necessary) of the type of entity indicated by the type parameter.  So the method the user of the library would use would look something like:

EntityService.All( ParentEntityId, OtherRelatedId, ListOfYetOtherRelatedIds )

This can greatly reduce the amount of simple inner join queries necessary in your repository.  You can find it at codeplex.  Hope someone else finds it useful.

Wednesday, October 24, 2012

MSBuild incorrectly skips projects set to build for given configuration

I ran into this problem and couldn't find any solutions for it anywhere. I was using MSBuild with VS2012. When I tried to build my solution, there seemed not to be any rhyme or reason as to what projects it chose to build. I would get this message in the log:

The project "[MyProject]" is not selected for building in solution configuration "Debug|Any CPU".

If I opened the solution, opened the Build Configuration Manager, ensured "Debug" was selected under "Active solution configuration", looked at my project, ensured "Any CPU" was selected under platform, I could see that the box in the "Build" column was checked. Most (but not all) that were unchecked were built.

The solution for me was to just create a new solution configuration (an option in the "Active solution configuration" drop list). I named it "ForMSBuild" so as not to confuse other devs, and selected to copy the settings from Debug. I selected "Any CPU" in the "Active solution platform" drop list, ensured each project had "Any CPU" selected and made my "Build" selections as necessary. After adjusting the params passed to MSBuild to refer to this new configuration, it built correctly.

Update:  I later found that builds were run directly in visual studio using the main Debug configuration.  I was getting build errors in deprecated test projects that were set to not build in the configuration.  I'm convinced there is a bug in 2012.

Tuesday, March 27, 2012

Using EPPlus Library to Convert XLSX to CSV

The EPPlus library for Excel data is great, but it has no built-in functionality for converting .xlsx to .csv.

Here is a sample (posted here because I discovered a pitfall, and it's not a slam dunk) for doing just that.  It's a single file, console app, just add EPPlus via nuget.

Update: Prior code was no good for large files (and said so).  Updated to work with giant files.


Wednesday, January 25, 2012

WPF Mapping / Association Control

When importing data from one store to another, many applications allow visual "mapping" of source fields to destination fields where lines are drawn to connect the two.
I tried in vain to find some kind of WPF/Xaml control that would do that, so I created one:

The control (regular user control) would be useful for any kind of association between two sets of data. The user creates associations by dragging from source to destination. It has a mode for one-to-one (a source item can only be mapped to one destination item) and one-to-many. Moving the scroll bars of the lists redraws the association lines appropriately. It's done MVVC style with models for the control as a whole and for the lists that hold the fields.

I was amazed at how easy this was to do with Xaml. I'm only a recent Xaml user, and when I use it I'm so pleased and dismayed at the same time. Pleased because it's such a rich, well thought out technology. Dismayed because MS has been forced to essentially abandon it in favor of the tyranny of HTML. I wonder how much more difficult this same thing would be to do using HTML5.

Source code here. Hope someone else can make use of it.