Example #1
0
        public DLinqTableProvider(DLinqDataModelProvider dataModel, MetaType rowType, string name, PropertyInfo prop)
            : base(dataModel)
        {
            _prop    = prop;
            _rowType = rowType;
            Name     = name;
            DataContextPropertyName = prop.Name;
            EntityType       = rowType.Type;
            ParentEntityType = rowType.InheritanceBase != null ? rowType.InheritanceBase.Type : null;
            RootEntityType   = rowType.Table.RowType.Type;

            _columns = new List <ColumnProvider>();
            var members = new List <MetaDataMember>(rowType.DataMembers);

            // Add in base-class-first order (not the typical derived-class-first order)
            foreach (PropertyInfo propInfo in GetOrderedProperties(rowType.Type))
            {
                MetaDataMember member = members.FirstOrDefault(m => m.Member.Name == propInfo.Name);
                if (member != null)
                {
                    AddColumn(dataModel, member, propInfo);
                    members.Remove(member);
                }
            }

            // Anything we might've missed, tack it onto the end
            foreach (MetaDataMember member in members)
            {
                AddColumn(dataModel, member, (PropertyInfo)member.Member);
            }

            _roColumns = new ReadOnlyCollection <ColumnProvider>(_columns);
        }
        public DLinqTableProvider(DLinqDataModelProvider dataModel, MetaType rowType, string name, PropertyInfo prop)
            : base(dataModel) {
            _prop = prop;
            _rowType = rowType;
            Name = name;
            DataContextPropertyName = prop.Name;
            EntityType = rowType.Type;
            ParentEntityType = rowType.InheritanceBase != null ? rowType.InheritanceBase.Type : null;
            RootEntityType = rowType.Table.RowType.Type;

            _columns = new List<ColumnProvider>();
            var members = new List<MetaDataMember>(rowType.DataMembers);

            // Add in base-class-first order (not the typical derived-class-first order)
            foreach (PropertyInfo propInfo in GetOrderedProperties(rowType.Type)) {
                MetaDataMember member = members.FirstOrDefault(m => m.Member.Name == propInfo.Name);
                if (member != null) {
                    AddColumn(dataModel, member, propInfo);
                    members.Remove(member);
                }
            }

            // Anything we might've missed, tack it onto the end
            foreach (MetaDataMember member in members) {
                AddColumn(dataModel, member, (PropertyInfo)member.Member);
            }

            _roColumns = new ReadOnlyCollection<ColumnProvider>(_columns);
        }
        private void AddColumn(DLinqDataModelProvider dataModel, MetaDataMember member, PropertyInfo propInfo) {
            var publicGetAccessor = propInfo.GetGetMethod();
            if (publicGetAccessor == null) {
                // the property at least needs to have a public getter, otherwise databinding will not work
                return;
            }

            DLinqColumnProvider column = new DLinqColumnProvider(this, member);
            _columns.Add(column);

            if (!dataModel.ColumnLookup.ContainsKey(propInfo))
                dataModel.ColumnLookup[propInfo] = column;
        }
        private void SetOtherEndOfAssociation(MetaAssociation association)
        {
            DLinqTableProvider     entityMemberParentEntity = (DLinqTableProvider)FromColumn.Table;
            DLinqDataModelProvider parentEntityDataContext  = (DLinqDataModelProvider)entityMemberParentEntity.DataModel;

            if (association.OtherMember != null)
            {
                ToColumn = parentEntityDataContext.ColumnLookup[(PropertyInfo)association.OtherMember.Member];
            }
            else
            {
                ToTable = ((DLinqDataModelProvider)FromColumn.Table.DataModel).DLinqTables.Single(tp => tp.EntityType == association.OtherType.Type);
            }
        }
Example #5
0
        private void AddColumn(DLinqDataModelProvider dataModel, MetaDataMember member, PropertyInfo propInfo)
        {
            var publicGetAccessor = propInfo.GetGetMethod();

            if (publicGetAccessor == null)
            {
                // the property at least needs to have a public getter, otherwise databinding will not work
                return;
            }

            DLinqColumnProvider column = new DLinqColumnProvider(this, member);

            _columns.Add(column);

            if (!dataModel.ColumnLookup.ContainsKey(propInfo))
            {
                dataModel.ColumnLookup[propInfo] = column;
            }
        }