예제 #1
0
        public override MetaDataMember GetDataMember(MemberInfo mi)
        {
            if (mi == null)
            {
                throw ALinq.Error.ArgumentNull("mi");
            }
            MetaDataMember member = null;

            //ALinq 2.6.3 添加功能,实体类通过继承 Interface 接口,通过接口可以进行查询。
            if (mi.DeclaringType.IsInterface)
            {
                var bf = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                         BindingFlags.GetField | BindingFlags.GetProperty;
                var m = Type.GetMember(mi.Name, bf);
                if (m.Length > 0)
                {
                    mi = m[0];
                }
            }
            //===================================================

            if (this.dataMemberMap.TryGetValue(new MetaPosition(mi), out member))
            {
                return(member);
            }
            if (mi.DeclaringType.IsInterface)
            {
                throw Mapping.Error.MappingOfInterfacesMemberIsNotSupported(mi.DeclaringType.Name, mi.Name);
            }
            throw Mapping.Error.UnmappedClassMember(mi.DeclaringType.Name, mi.Name);
        }
예제 #2
0
 private void ValidatePrimaryKeyMember(MetaDataMember mm)
 {
     if ((mm.IsPrimaryKey && (this.inheritanceRoot != this)) && (mm.Member.DeclaringType == this.type))
     {
         throw Mapping.Error.PrimaryKeyInSubTypeNotSupported(this.type.Name, mm.Name);
     }
 }
예제 #3
0
 private void InitSpecialMember(MetaDataMember mm)
 {
     if ((mm.IsDbGenerated && mm.IsPrimaryKey) && string.IsNullOrEmpty(mm.Expression))
     {
         if (this.dbGeneratedIdentity != null)
         {
             throw Mapping.Error.TwoMembersMarkedAsPrimaryKeyAndDBGenerated(mm.Member, this.dbGeneratedIdentity.Member);
         }
         this.dbGeneratedIdentity = mm;
     }
     if (mm.IsPrimaryKey && !MappingSystem.IsSupportedIdentityType(mm.Type))
     {
         throw Mapping.Error.IdentityClrTypeNotSupported(mm.DeclaringType, mm.Name, mm.Type);
     }
     if (mm.IsVersion)
     {
         if (this.version != null)
         {
             throw Mapping.Error.TwoMembersMarkedAsRowVersion(mm.Member, this.version.Member);
         }
         this.version = mm;
     }
     if (mm.IsDiscriminator)
     {
         if (this.discriminator != null)
         {
             throw Mapping.Error.TwoMembersMarkedAsInheritanceDiscriminator(mm.Member, this.discriminator.Member);
         }
         this.discriminator = mm;
     }
 }
예제 #4
0
        // Methods
        internal AttributedMetaAssociation(AttributedMetaDataMember member, AssociationAttribute attr)
        {
            this.attributeProvider = member.MetaModel.AttributeProvider;

            this.thisMember = member;
            this.isMany     = TypeSystem.IsSequenceType(thisMember.Type);
            Type type = this.isMany ? TypeSystem.GetElementType(thisMember.Type) : thisMember.Type;

            this.otherType            = this.thisMember.DeclaringType.Model.GetMetaType(type);
            this.thisKey              = (attr.ThisKey != null) ? MakeKeys(thisMember.DeclaringType, attr.ThisKey) : thisMember.DeclaringType.IdentityMembers;
            this.otherKey             = (attr.OtherKey != null) ? MakeKeys(otherType, attr.OtherKey) : this.otherType.IdentityMembers;
            this.thisKeyIsPrimaryKey  = AreEqual(this.thisKey, thisMember.DeclaringType.IdentityMembers);
            this.otherKeyIsPrimaryKey = AreEqual(this.otherKey, otherType.IdentityMembers);
            this.isForeignKey         = attr.IsForeignKey;
            this.isUnique             = attr.IsUnique;
            this.deleteRule           = attr.DeleteRule;
            this.deleteOnNull         = attr.DeleteOnNull;
            foreach (MetaDataMember member2 in this.thisKey)
            {
                if (!member2.CanBeNull)
                {
                    this.isNullable = false;
                    break;
                }
            }
            if (this.deleteOnNull && ((!this.isForeignKey || this.isMany) || this.isNullable))
            {
                throw Mapping.Error.InvalidDeleteOnNullSpecification(member);
            }
            if (((this.thisKey.Count != this.otherKey.Count) && (this.thisKey.Count > 0)) && (this.otherKey.Count > 0))
            {
                throw Mapping.Error.MismatchedThisKeyOtherKey(member.Name, member.DeclaringType.Name);
            }
            foreach (MetaDataMember member3 in this.otherType.PersistentDataMembers)
            {
                /* var customAttribute = (AssociationAttribute)Attribute.GetCustomAttribute(member3.Member, typeof(AssociationAttribute)); */
                var customAttribute = this.attributeProvider.GetAssociationAttribute(member3.Member);

                if (((customAttribute != null) && (member3 != this.thisMember)) && (customAttribute.Name == attr.Name))
                {
                    this.otherMember = member3;
                    break;
                }
            }
        }
예제 #5
0
 private void InitOther()
 {
     if (this.otherType == null)
     {
         Type type = this.isMany ? TypeSystem.GetElementType(this.thisMember.Type) : this.thisMember.Type;
         this.otherType            = this.thisMember.DeclaringType.Model.GetMetaType(type);
         this.otherKey             = (this.assocMap.OtherKey != null) ? MetaAssociationImpl.MakeKeys(this.otherType, this.assocMap.OtherKey) : this.otherType.IdentityMembers;
         this.otherKeyIsPrimaryKey = MetaAssociationImpl.AreEqual(this.otherKey, this.otherType.IdentityMembers);
         foreach (MetaDataMember member in this.otherType.DataMembers)
         {
             if ((member.IsAssociation && (member != this.thisMember)) && (member.MappedName == this.thisMember.MappedName))
             {
                 this.otherMember = member;
                 break;
             }
         }
     }
 }
예제 #6
0
 protected static ReadOnlyCollection <MetaDataMember> MakeKeys(MetaType mtype, string keyFields)
 {
     string[]         strArray   = keyFields.Split(keySeparators);
     MetaDataMember[] collection = new MetaDataMember[strArray.Length];
     for (int i = 0; i < strArray.Length; i++)
     {
         strArray[i] = strArray[i].Trim();
         MemberInfo[] member = mtype.Type.GetMember(strArray[i], BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
         if ((member == null) || (member.Length != 1))
         {
             throw Error.BadKeyMember(strArray[i], keyFields, mtype.Name);
         }
         collection[i] = mtype.GetDataMember(member[0]);
         if (collection[i] == null)
         {
             throw Error.BadKeyMember(strArray[i], keyFields, mtype.Name);
         }
     }
     return(new List <MetaDataMember>(collection).AsReadOnly());
 }
예제 #7
0
 protected override SqlExpression GetReturnIdentityExpression(ALinq.Mapping.MetaDataMember idMember, bool isOutputFromInsert)
 {
     //return new SqlVariable(typeof(int), typeProvider.From(typeof(int)), " LAST_INSERT_ROWID()", this.dominatingExpression);
     return(sql.FunctionCall(typeof(int), "LAST_INSERT_ROWID", new SqlExpression[] { }, dominatingExpression));
 }