Esempio n. 1
0
        /// <exclude />
        public static IData GetReferenced(this IData refereeData, string foreignKeyPropertyName)
        {
            Verify.ArgumentNotNull(refereeData, "refereeData");
            Verify.ArgumentNotNullOrEmpty(foreignKeyPropertyName, "foreignKeyPropertyName");

            ForeignPropertyInfo foreignPropertyInfo =
                (from fkpi in DataReferenceRegistry.GetForeignKeyProperties(refereeData.DataSourceId.InterfaceType)
                 where fkpi.SourcePropertyName == foreignKeyPropertyName
                 select fkpi).Single();

            object sourceKeyValue = foreignPropertyInfo.SourcePropertyInfo.GetValue(refereeData, null);

            // Handling of Nullable<>
            if (sourceKeyValue == null)
            {
                return(null);
            }

            Type targetType = foreignPropertyInfo.TargetType;
            var  dataset    = DataFacade.GetData(targetType);

            IEnumerable queryResult = GetReferences(dataset, targetType, foreignPropertyInfo.TargetKeyPropertyInfo, sourceKeyValue, true);

            foreach (var result in queryResult)
            {
                Verify.That(result is IData, "Query result should implement '{0}' interface", typeof(IData).FullName);
                return(result as IData);
            }
            return(null);
        }
Esempio n. 2
0
        private static bool HasReference(IQueryable queryable, ForeignPropertyInfo foreignPropertyInfo, object propertyValue)
        {
            var targetType = foreignPropertyInfo.TargetType;

            var methodInfo = HasReferenceMethodInfo.MakeGenericMethod(new[] { targetType });

            return((bool)methodInfo.Invoke(null, new[] { queryable, foreignPropertyInfo.TargetKeyPropertyInfo, propertyValue }));
        }
Esempio n. 3
0
        internal static bool CascadeDeleteAllowed(this IData data)
        {
            Verify.ArgumentNotNull(data, "data");

            ForeignPropertyInfo foreignPropertyInfo =
                (from pi in DataReferenceRegistry.GetForeignKeyProperties(data.DataSourceId.InterfaceType)
                 where pi.AllowCascadeDeletes == false
                 select pi).FirstOrDefault();

            return(foreignPropertyInfo == null);
        }
Esempio n. 4
0
        /// <exclude />
        public static bool TryGetReferenceType(this PropertyInfo propertyInfo, out Type typeBeingReferenced)
        {
            Verify.ArgumentNotNull(propertyInfo, "propertyInfo");

            typeBeingReferenced = null;

            lock (_lock)
            {
                if (_propertyReferenceTargetTypeLookup.TryGetValue(propertyInfo, out typeBeingReferenced) == false)
                {
                    IEnumerable <ForeignPropertyInfo> foreignKeysOnType = DataReferenceRegistry.GetForeignKeyProperties(propertyInfo.DeclaringType);
                    ForeignPropertyInfo match = foreignKeysOnType.FirstOrDefault(f => f.SourcePropertyName == propertyInfo.Name);

                    typeBeingReferenced = (match != null ? match.TargetType : null);

                    _propertyReferenceTargetTypeLookup.Add(propertyInfo, typeBeingReferenced);
                }
            }

            return(typeBeingReferenced != null);
        }
Esempio n. 5
0
        private static IEnumerable GetReferences(IQueryable queryable, ForeignPropertyInfo foreignPropertyInfo, object keyValue, bool justOne)
        {
            Type sourceType = foreignPropertyInfo.SourcePropertyInfo.DeclaringType;

            return(GetReferences(queryable, sourceType, foreignPropertyInfo.SourcePropertyInfo, keyValue, justOne));
        }