anchor.diff:      | AttributeTypeCode.Customer  
       | AttributeTypeCode.Owner     -> TsType.String, SpecialType.EntityReference
           
  -    | AttributeTypeCode.Uniqueidentifier -> TsType.String, SpecialType.Guid
  -    | AttributeTypeCode.Decimal   -> 
  -      toSome typeConv a.AttributeType, SpecialType.Decimal
  -    | _ -> toSome typeConv a.AttributeType, SpecialType.Default
  +    | AttributeTypeCode.Uniqueidentifier 
  +                                  -> TsType.String, SpecialType.Guid
   
  -  let attr = 
  -    match a.IsValidForCreate.GetValueOrDefault(false) <> a.IsValidForUpdate.GetValueOrDefault(false) with
  -    | true -> Some a
  -    | false -> None
  +    | AttributeTypeCode.Decimal   -> toSome typeConv a.AttributeType, SpecialType.Decimal
  +    | _                           -> toSome typeConv a.AttributeType, SpecialType.Default
   
  -  if attr.IsSome then
  -    ()
   
     options, Some {
       XrmAttribute.schemaName = a.SchemaName
  
positive.code:           else rel.ReferencedEntityNavigationPropertyName
          referencing = referencing
          relatedSetName = rSetName
          relatedSchemaName = rSchema }
  
      rSchema, xRel
  
  
  let interpretM2MRelationship schemaNames map lname (rel:ManyToManyRelationshipMetadata) =
    let rLogical =
      match lname = rel.Entity2LogicalName with
      | true  -> rel.Entity1LogicalName
      | false -> rel.Entity2LogicalName
      
    Map.tryFind rLogical map
    ?>>? fun (rSchema, _) -> Set.contains rSchema schemaNames
    ?|> (fun (rSchema, rSetName) ->
        
      let xRel = 
        { XrmRelationship.schemaName = rel.SchemaName 
          attributeName = rel.SchemaName
          navProp = 
            if lname = rel.Entity2LogicalName then rel.Entity1NavigationPropertyName
            else rel.Entity2NavigationPropertyName
          referencing = false
          relatedSetName = rSetName
          relatedSchemaName = rSchema }
      
      rSchema, xRel)
  
  
  let interpretEntity schemaNames map (metadata:EntityMetadata) =
    if (metadata.Attributes = null) then failwith "No attributes found!"
  
    let opt_sets, attr_vars = 
      metadata.Attributes 
      |> Array.map (interpretAttribute map schemaNames)
      |> Array.unzip
  
    let attr_vars = attr_vars |> Array.choose id |> Array.toList
      
    let opt_sets = 
      opt_sets |> Seq.choose id 
      |> Seq.distinctBy (fun x -> x.displayName) 
      |> Seq.toList
      
  
    let handleOneToMany referencing = function
      | null -> Array.empty
      | x -> x |> Array.choose (interpretRelationship schemaNames map referencing)
      
    let handleManyToMany logicalName = function
      | null -> Array.empty
      | x -> x |> Array.choose (interpretM2MRelationship schemaNames map logicalName)
  
  
    let rel_entities, rel_vars = 
      [ metadata.OneToManyRelationships |> handleOneToMany false 
        metadata.ManyToOneRelationships |> handleOneToMany true 
        metadata.ManyToManyRelationships |> handleManyToMany metadata.LogicalName 
      ] |> List.map Array.toList
        |> List.concat
        |> List.unzip
  
    let rel_entities = 
      rel_entities 
      |> Set.ofList |> Set.remove metadata.SchemaName |> Set.toList
  
    { XrmEntity.typecode = metadata.ObjectTypeCode.GetValueOrDefault()
      schemaName = metadata.SchemaName
  
negative.code:     attrs = attr_vars
      rels = rel_vars
      opt_sets = opt_sets
      relatedEntities = rel_entities 
    }