Exemplo n.º 1
0
        private async ValueTask LoadFieldAsync(Entity owner, ReadonlyTransaction txn)
        {
            //TODO:*****暂简单实现,待存储引擎实现Select指定字段集后修改
            var path1 = await LoadFieldPath(owner, MemberId1, txn);

            if (path1 == null)
            {
                owner.AddAttached(AliasName, null);
                return;
            }

            var mm2 = path1.Model.GetMember(MemberId2, true);

            if (mm2.Type != EntityMemberType.EntityRef)
            {
                owner.AddAttached(AliasName, path1.GetMember(MemberId2).BoxedValue);
                return;
            }

            var path2 = await LoadFieldPath(path1, MemberId2, txn);

            if (path2 == null)
            {
                owner.AddAttached(AliasName, null);
                return;
            }

            Debug.Assert(path2.Model.GetMember(MemberId3, true).Type != EntityMemberType.EntityRef);
            owner.AddAttached(AliasName, path2.GetMember(MemberId3).BoxedValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据成员路径填充相应的成员的值
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="path">eg: Order.Customer.ID or Name</param>
        private static void FillMemberValue(Entity target, ReadOnlySpan <char> path, DbDataReader reader, int clIndex)
        {
            if (reader.IsDBNull(clIndex)) //null直接跳过
            {
                return;
            }

            var indexOfDot = path.IndexOf('.');

            if (indexOfDot < 0)
            {
                ref EntityMember m = ref target.TryGetMember(path, out bool found);
                if (!found) //不存在的作为附加成员
                {
                    target.AddAttached(path.ToString(), reader.GetValue(clIndex));
                }
                else
                {
                    //Log.Warn($"Fill {target.Model.Name}.{path.ToString()} value={reader.GetValue(clIndex).ToString()}");
                    m.Flag.HasLoad = m.Flag.HasValue = true;
                    switch (m.ValueType)
                    {
                    case EntityFieldType.String: m.ObjectValue = reader.GetString(clIndex); break;

                    case EntityFieldType.Binary: m.ObjectValue = (byte[])reader.GetValue(clIndex); break;

                    case EntityFieldType.Guid: m.GuidValue = reader.GetGuid(clIndex); break;

                    case EntityFieldType.Decimal: m.DecimalValue = reader.GetDecimal(clIndex); break;

                    case EntityFieldType.DateTime: m.DateTimeValue = reader.GetDateTime(clIndex); break;

                    case EntityFieldType.Double: m.DoubleValue = reader.GetDouble(clIndex); break;

                    case EntityFieldType.Float: m.FloatValue = reader.GetFloat(clIndex); break;

                    case EntityFieldType.Enum: m.Int32Value = reader.GetInt32(clIndex); break;

                    case EntityFieldType.Int64: m.Int64Value = reader.GetInt64(clIndex); break;

                    case EntityFieldType.UInt64: m.UInt64Value = unchecked ((ulong)reader.GetInt64(clIndex)); break;

                    case EntityFieldType.Int32: m.Int32Value = reader.GetInt32(clIndex); break;

                    case EntityFieldType.UInt32: m.UInt32Value = unchecked ((uint)reader.GetInt32(clIndex)); break;

                    case EntityFieldType.Int16: m.Int16Value = reader.GetInt16(clIndex); break;

                    case EntityFieldType.UInt16: m.UInt16Value = unchecked ((ushort)reader.GetInt16(clIndex)); break;

                    case EntityFieldType.Byte: m.ByteValue = reader.GetByte(clIndex); break;

                    case EntityFieldType.Boolean: m.BooleanValue = reader.GetBoolean(clIndex); break;

                    default: throw new NotSupportedException(m.ValueType.ToString());
                    }
                }
            }