title: Building a Repository using ServiceStack.ORMLite
body: <p>I'm using servicestack and i'm planning to use ormlite for the data access layer.
  I've these tables (SQL Server 2005)</p>
  
  <pre><code>Table ITEM
  ID PK
  ...
  
  Table SUBITEM1
  ID PK FK -&gt; ITEM(ID)
  ...
  
  Table SUBITEM2
  ID PK FK -&gt; ITEM(ID)
  ...
  
  Table POST
  ID PK
  ...
  
  Table COMMENT
  ID PK
  ...
  
  Table DOWNLOAD
  ID PK
  ...
  
  Table POST_COMMENT
  ID PK
  POST_ID FK -&gt; POST(ID)
  COMMENT_ID FK -&gt; COMMENT(ID)
  
  Table DOWNLOAD_COMMENT
  ID PK
  DOWNLOAD_ID FK -&gt; DOWNLOAD(ID)
  COMMENT_ID FK -&gt; COMMENT(ID)
  </code></pre>
  
  <p>I created a class for each table and mapped them using annotations (autoincrement, references, etc).</p>
  
  <p>I decided to creare a repository for each "entity" (item, post, comment, download).
  Each repository contains the basic CRUD logic, </p>
  
  <p>eg. 1 CommentRepository has a Save(Comment comment, Object relationship) that performs db.Insert(comment, relationship) where relationship is PostComment or DownloadComment.</p>
  
  <p>eg. 2 PostRepository has a Save(Post p) that performs the insert into POST.</p>
  
  <p>I'm not sure about this solution because the repository interface is different and I can't do polymorphic queries.</p>
  
  <p>Can you provide any advice to improve my DAL?</p>
  
  <p>Thank you for your attention.</p>