示例#1
0
        public override MemberExpression this[string name]
        {
            get
            {
                MemberExpression exp = null;
                if (Cache.TryGetValue(name, out exp))
                {
                    return(exp);
                }

                EntityModel       model = Runtime.RuntimeContext.Current.GetModelAsync <EntityModel>(ModelID).Result;
                EntityMemberModel m     = model.GetMember(name, false);
                if (m != null)
                {
                    switch (m.Type)
                    {
                    case EntityMemberType.DataField:
                        //case EntityMemberType.Formula:
                        //case EntityMemberType.Aggregate:
                        //case EntityMemberType.AutoNumber:
                        exp = new FieldExpression(name, this);
                        break;

                    case EntityMemberType.EntityRef:
                        var rm = (EntityRefModel)m;
                        if (!rm.IsAggregationRef)
                        {
                            exp = new EntityExpression(name, rm.RefModelIds[0], this);
                        }
                        else
                        {
                            throw new NotImplementedException("尚未实现聚合引用对象的表达式");
                        }
                        break;

                    case EntityMemberType.EntitySet:
                        var sm = (EntitySetModel)m;
                        //EntityRefModel erm = esm.RefModel[esm.RefMemberName] as EntityRefModel;
                        exp = new EntitySetExpression(name, this, sm.RefModelId);
                        break;

                    //case EntityMemberType.AggregationRefField:
                    //    exp = new AggregationRefFieldExpression(name, this);
                    //    break;
                    default:
                        throw new NotSupportedException($"EntityExpression.DefaultIndex[]: Not Supported MemberType [{m.Type.ToString()}].");
                    }
                    Cache.Add(name, exp);
                    return(exp);
                }
                //如果不包含判断是否继承,或EntityRef's DisplayText
                //if (name.EndsWith("DisplayText", StringComparison.Ordinal)) //TODO: 暂简单判断
                //{
                //    exp = new FieldExpression(name, this);
                //    Cache.Add(name, exp);
                //    return exp;
                //}
                throw new Exception($"Can not find member [{name}] in [{model.Name}].");
            }
        }
示例#2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            EntitySetExpression target = obj as EntitySetExpression;

            if (Equals(null, target))
            {
                return(false);
            }

            return(Equals(target.Owner, Owner) && target.Name == Name);
        }