tags:

views:

241

answers:

2

I have this Document table with some meta data for the document in it and also the document content as a blob.

then I use lucene.Net to query my documents; which in return gives me a list of Guids to my Document table and also two fields containing the highlighted html versions of the document name and extract with the search keywords highlighted.

then I use linq to join this result with my document table fields to get a list to show as the search result. stupid thing is linq tries to load the blob to the document although it's not used in the join.

I'm thinking of two options, neither of them I like:

  • move my blob to a new table and link it 1-1 to the document table. which I don't like because the limitation in linq is forcing me to change my db structure.
  • add a new dbml with a "LiteDocument" table in it and remove the blob from the document table in dbml; which I don't like because I have two places to maintain if document table has a change.

I was wondering if there is a better way to do this? here are the code snippets:

 public class LuceneSearchResult
 {
  public Guid DocumentID { get; set; }
  public string FormattedDocumentFileName { get; set; }
  public string FormattedDocumentExtract { get; set; }
 }

and

 public IList Search(string searchPhrase, Guid? ProductId)
 {
  searchPhrase = PrepareSearchPhraseWithThesaurus(searchPhrase);
  var result = RunLuceneQuery(searchPhrase, ProductId);

  var dc = new ChinaHcpDataContext();
  var docs =
    from r in result
    join d in dc.Documents on r.DocumentID equals d.DocumentID
    select
      new
        {
         d.DocumentID,
         TradeNameEN = d.TradeProduct != null ? d.TradeProduct.TradeNameEN : "",
         TradeNameZH = d.TradeProduct != null ? d.TradeProduct.TradeNameZH : "",
         d.DocumentFileName,
         d.InsertedDateUtc,
         d.Size,
         DocumentDisplayText = r.FormattedDocumentFileName,
         DocumentSelectionReason = r.FormattedDocumentExtract
        };

  return docs.ToList();
 }
A: 

Would it help to create a View in your database that excludes the blob, and then generate your dbml from the view? It's not too terribly different from your second option, but keeps the changes mainly in the database itself, without requiring any changes to your existing table structure.

Joel Mueller
+2  A: 

You can specify that a field is delay loaded. Its one of the properties available for table fields in the DBML designer.

Frank Schwieterman
Delay-loaded fields are the way to go. I believe the actual value of a delay-loaded field is only fetched from the DB when its property accessor is invoked (e.g. myDoc.Blob). So the blob is only actually fetched when it's really needed.
Saajid Ismail