anchor.diff:      | EdmType.String -> builder typeof<string>
       | _ -> builder typeof<obj>
   
  -let buildParameter name buildType = ProvidedParameter(name, buildType)
  -
   /// Sets the properties on a specific entity based on the inferred schema from the sample provided
   let setPropertiesForEntity (entityType : ProvidedTypeDefinition) (sampleEntities : #seq<DynamicTableEntity>) = 
  -    let properties = sampleEntities |> getDistinctProperties
  +    let properties = sampleEntities |> Seq.map getPropsForEntity |> getDistinctProperties
       entityType.AddMembersDelayed(fun _ -> 
           properties
           |> Seq.map (fun (name, edmType, need) -> 
  
positive.code:                 let optionals = (mandatory - entity) + (entity - mandatory) + optionals
                  let mandatory = Set.intersect mandatory entity
                  optionals, mandatory, false)
      (optionalProperties |> Set.toList |> List.map(fun (name, edmType) -> name, edmType, PropertyNeed.Optional)) @
      (mandatoryProperties |> Set.toList |> List.map(fun (name, edmType) -> name, edmType, PropertyNeed.Mandatory))
      |> List.sortBy(fun (name, _, _) -> name)
  
  /// Builds a property for a single entity for a specific type
  let private buildEntityProperty<'a> key need = 
      let getter = 
          match need with
          | PropertyNeed.Mandatory ->
              fun (args : Expr list) -> 
                  <@@ let entity = (%%args.[0] : LightweightTableEntity)
                      if entity.Values.ContainsKey(key) then entity.Values.[key] :?> 'a
                      else Unchecked.defaultof<'a> @@>
          | PropertyNeed.Optional ->
              fun (args : Expr list) -> 
                  <@@ let entity = (%%args.[0] : LightweightTableEntity)
                      if entity.Values.ContainsKey(key) then Some(entity.Values.[key] :?> 'a)
                      else None @@>
      
      let propType = match need with | PropertyNeed.Optional -> typeof<Option<'a>> | _ -> typeof<'a> 
  
      let prop = ProvidedProperty(key, propType, GetterCode = getter)
      prop.AddXmlDocDelayed <| fun _ -> (sprintf "Returns the value of the %s property" key)
      prop
  
negative.code:                | _ -> buildEntityProperty<obj> name need)
          |> Seq.toList)
      
      let buildParameter name need buildType =
          match need with
          | Mandatory -> ProvidedParameter(name, buildType)
          | Optional -> ProvidedParameter(name, buildType, optionalValue = true)
  
      // Build a constructor as well.
      entityType.AddMemberDelayed(fun () -> 
          // Split into mandatory and optional parameters - we add the mandatory ones first.
          let mandatoryParams, optionalParams = properties |> List.partition(function (_,_, Mandatory) -> true | _ -> false) 
          let parameters = 
              [ ProvidedParameter("PartitionKey", typeof<Partition>)
                ProvidedParameter("RowKey", typeof<Row>) ] 
              @ [ for (name, edmType, need) in mandatoryParams -> buildEdmParameter edmType (buildParameter name need) ]
              @ [ for (name, edmType, need) in optionalParams -> buildEdmParameter edmType (buildParameter name need) ]
          ProvidedConstructor(
              parameters, 
              InvokeCode = fun args ->
                  printfn "Args: %A" (args |> List.map(fun a -> a, a.Type))
                  let fieldValues = 
                      args
                      |> Seq.skip 2
                      |> Seq.map (fun arg -> Expr.Coerce(arg, typeof<obj>))
                      |> Seq.toList
  
                  printfn "Values: %A" fieldValues
                  let fieldNames =
                      (mandatoryParams @ optionalParams)
                      |> Seq.take fieldValues.Length
                      |> Seq.map(fun (name, _, _) -> name)
                      |> Seq.toList
                  printfn "Names: %A" fieldNames
                  <@@ buildTableEntity (%%args.[0] : Partition) (%%args.[1] : Row) fieldNames (%%(Expr.NewArray(typeof<obj>, fieldValues))) @@>))
      properties
  
  