Ejemplo n.º 1
0
        internal EntityKey Coerce(EntityType entityType = null)
        {
            if (entityType == null)
            {
                if (EntityType == null)
                {
                    throw new Exception("No EntityType to coerce into");
                }
            }
            else
            {
                if (EntityType != null && EntityType != entityType)
                {
                    throw new Exception("Cannot coerce entityKey: " + this + " to : " + entityType);
                }
                _entityType = entityType;
                ClrType     = _entityType.ClrType;
            }

            for (int i = 0; i < Values.Length; i++)
            {
                var clrType = EntityType.KeyProperties[i].ClrType;
                var val     = Values[i];
                if (val == null)
                {
                    continue;
                }
                if (clrType != val.GetType())
                {
                    Values[i] = TypeFns.ConvertType(val, clrType, false);
                }
            }
            return(this);
        }
Ejemplo n.º 2
0
 private void Coerce()
 {
     for (int i = 0; i < Values.Length; i++)
     {
         var clrType = EntityType.KeyProperties[i].ClrType;
         var val     = Values[i];
         if (val == null)
         {
             continue;
         }
         if (clrType != val.GetType())
         {
             Values[i] = TypeFns.ConvertType(val, clrType, true);
         }
     }
 }