Exemple #1
0
        public static void RegisterMMLookup(ManyToManyRelationshipAttribute mmr, Type relType)
        {
            CheckMMSupport(mmr.First);
            CheckMMSupport(mmr.Second);

            string firstKey  = null,
                   secondKey = null;

            foreach (var p in relType.GetProperties())
            {
                AssociationAttribute aa;
                if (p.TryGetAtr(out aa))
                {
                    if (p.PropertyType == mmr.First && p.PropertyType == mmr.Second)
                    {
                        if (firstKey == null)
                        {
                            firstKey = aa.ThisKey;
                        }
                        else if (secondKey == null)
                        {
                            secondKey = aa.ThisKey;
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    else if (p.PropertyType == mmr.First)
                    {
                        if (firstKey != null)
                        {
                            throw new InvalidOperationException();
                        }
                        firstKey = aa.ThisKey;
                    }
                    else if (p.PropertyType == mmr.Second)
                    {
                        if (secondKey != null)
                        {
                            throw new InvalidOperationException();
                        }
                        secondKey = aa.ThisKey;
                    }
                }
            }
            if (firstKey.IsNull() || secondKey.IsNull())
            {
                throw new DMError(Translations.LookupHelper_RegisterMMLookup_Invalid_many_to_many_relationship_definition_for__0___1_, mmr.First.Name, mmr.Second.Name);
            }
            string tableName = SqlSerializationContext.ExtractTableName(relType.GetAtr <TableAttribute>().Name);

            Put(__MMInfos, mmr.First, mmr.Second, new ManyToManyLookupInfo(firstKey, tableName, secondKey, relType));
            Put(__MMInfos, mmr.Second, mmr.First, new ManyToManyLookupInfo(secondKey, tableName, firstKey, relType));
        }
Exemple #2
0
        static DataObjectInfo()
        {
            // Precalculation dataobject information
            Type type = typeof(TDataObject);
            var  ta   = type.GetAtr <TableAttribute>();

            TableName = SqlSerializationContext.ExtractTableName(ta.Name);

            Columns = new List <ColumnInfo>(
                from p in type.GetProperties()
                where p.HasAtr <ColumnAttribute>()
                select new ColumnInfo(type, p));
            ColumnNames = Columns.Select(c => SqlUtils.WrapDbId(c.Name)).ConcatComma();
            SelectSql   = "SELECT " + ColumnNames + " FROM " + SqlUtils.WrapDbId(TableName);
            IsSecured   = typeof(ISecuredDataObject).IsAssignableFrom(typeof(TDataObject));
        }
Exemple #3
0
 public static void RegisterLookup(Type ownerType, Type detailType, AssociationAttribute aa)
 {
     Put(__Infos, ownerType, detailType,
         new LookupInfo(aa.OtherKey, SqlSerializationContext.ExtractTableName(detailType.GetAtr <TableAttribute>().Name)));
 }