Posts

Showing posts from July, 2011

linq to lucene magic unicorn edition

This week I started to look at using Lucene.Net again in a project. Previously I have used it directly however whilst on the new look Lucene.Net website I noticed the linq to lucene project. Which at first look seemed pretty good. However upon looking at the source I found it only works with XML and LinqToSql, this prototype project however was in .Net 4 and used Sql CE4 with Entity Framework 4.1 Code First.




Rather than abandon linq to lucene I decided it should be easy enough to get it working with EF4.1. DatabaseIndexSet contains the LinqToSql specific code so for the purpose of producing a proof of concept this is where all the changes go.



The first item to change is to rescope the generic where clause to be DbContext rather than the linq context.

public class DatabaseIndexSet : IndexSet where TDataContext : DbContext
Next the Write Method needs altering, the LinqToSQL implementation uses the GetTable method, however E.F doesn't really have the same methods. Instead wit…