title: Instance Property is not defined for type 'System.Int64'
body: <p>I am using a Repository Pattern to access data using Entity Framework. I have implemented everything correctly (I think) using an onion architecture, but when I run tests I get the error :</p>
  
  <pre><code>Instance Property 'IDDocument' is not defined for type 'System.Int64'
  </code></pre>
  
  <p>(roughly translated from french)</p>
  
  <p>The method I test is the following:</p>
  
  <pre><code>public T Get(long id)
  {
      ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
      ObjectSet&lt;T&gt; set = objContext.CreateObjectSet&lt;T&gt;();
      IEnumerable&lt;string&gt; keyNames = set.EntitySet.ElementType
                                                  .KeyMembers
                                                  .Select(k =&gt; k.Name);
      if (keyNames.Count() &gt; 1)
          return null;//Que faire quand il y a plusieurs clés?
      else
      {
          string idName = keyNames.ElementAt(0); // For Document would be IDDocument
          var parameter = Expression.Parameter(id.GetType());
          var property = Expression.Property(parameter, idName);
          var idValue = Expression.Constant(id, id.GetType());
          var equal = Expression.Equal(property, idValue);
          var predicate = Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(equal, parameter);
          return entities.SingleOrDefault(predicate);
      }
  }
  </code></pre>
  
  <p>My tables have different ID names for reasons I won't explain, but this is why I used Expression builder to add parameters and then use a predicate to retrieve my result. You can see this method in this post: <a href="https://stackoverflow.com/questions/44591796/does-a-generic-repository-need-a-base-entity-class-to-be-applied-everywhere/44592318#44592318">Does a Generic Repository need a Base Entity class to be applied everywhere?</a></p>
  
  <p>IDDocument is declared in the following way in my EF entities' POCO:</p>
  
  <pre><code>[Key]
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public long IDDocument { get; set; }
  </code></pre>
  
  <p>And when I call it in my test:</p>
  
  <pre><code>[TestMethod]
  public void IdExistsGetTest()
  {
      long valueToCheck = 1L;
      repo = new Repository&lt;Web_Documents&gt;(context);
      var test = repo.Get(valueToCheck);
      test.Should().BeOfType(typeof(Web_Documents));
  }
  </code></pre>
  
  <p><code>context</code> defines my dbcontext (instantiated before).</p>
  
  <p>Now when I run the tests, I always get the ArgumentException stated above, any idea what I am missing? I think the problem resides in the Get(long id) method, because if I change the code without the <code>Expression</code>, it works fine (but not like i want it to!). Thanks</p>