Exemplo n.º 1
0
        // The logic that figures out the association is not yet ready.  For now we use the second implementation, which
        // gets us going until we iron things out
#if NOTYETREADY
        internal void Initialize()
        {
            if (DataServiceUtilities.IsEntityType(this.ColumnType, this.Table.DataModel.ContextType))
            {
                TableProvider tp = this.Table.DataModel.Tables
                                   .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType));

                if (tp != null)
                {
                    DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(tp)
                    {
                        ColumnType = typeof(string),
                        Name       = "Null(" + this.Table.Name + "." + this.Name + ")"
                    };
                    ((DataServiceTableProvider)tp).AddColumn(nullColumn);

                    Association = new DataServiceAssociationProvider(
                        AssociationDirection.ManyToOne,
                        this,
                        nullColumn,
                        new List <string>()
                    {
                        this.Table.Name + "({0})/" + this.Name
                    });
                }
            }
            // not the best heuristic, but it'll do for now
            else if (!DataServiceUtilities.IsPrimitiveType(this.ColumnType) &&
                     typeof(IEnumerable).IsAssignableFrom(this.ColumnType) &&
                     this.ColumnType.GetGenericArguments().Length > 0 &&
                     DataServiceUtilities.IsEntityType(this.ColumnType.GetGenericArguments()[0], this.Table.DataModel.ContextType))
            {
                TableProvider tp = this.Table.DataModel.Tables
                                   .FirstOrDefault(t => t.EntityType.IsAssignableFrom(this.ColumnType));

                if (tp != null)
                {
                    DataServiceColumnProvider nullColumn = new DataServiceColumnProvider(this.Table)
                    {
                        ColumnType = typeof(string),
                        Name       = "Null(" + this.Table.Name + "." + this.Name + ")"
                    };
                    ((DataServiceTableProvider)tp).AddColumn(nullColumn);

                    Association = new DataServiceAssociationProvider(
                        AssociationDirection.ManyToMany,
                        this,
                        nullColumn,
                        new List <string>()
                    {
                        this.Table.Name + "({0})/" + this.Name
                    });
                }
            }
        }
Exemplo n.º 2
0
 public static IEnumerable <PropertyInfo> EnumerateEntitySetProperties(Type contextType)
 {
     foreach (PropertyInfo prop in contextType.GetProperties())
     {
         if (typeof(IQueryable).IsAssignableFrom(prop.PropertyType) &&
             prop.PropertyType.GetGenericArguments().Length > 0 &&
             DataServiceUtilities.IsEntityType(prop.PropertyType.GetGenericArguments()[0], contextType))
         {
             yield return(prop);
         }
     }
 }