Exemple #1
0
        private IQueryOver <Document, TIndex> BindQueryOverByPath <TIndex>(string name)
        {
            IQueryOver <Document> queryOver;

            if (_joins.TryGetValue(name, out queryOver))
            {
                return((IQueryOver <Document, TIndex>)queryOver);
            }

            // public IList<{TIndex}> {TIndex} {get;set;}
            var dynamicMethod     = new DynamicMethod(typeof(TIndex).Name, typeof(IEnumerable <TIndex>), null, typeof(Document));
            var syntheticMethod   = new SyntheticMethodInfo(dynamicMethod, typeof(Document));
            var syntheticProperty = new SyntheticPropertyInfo(syntheticMethod);

            // doc => doc.{TIndex}
            var parameter           = Expression.Parameter(typeof(Document), "doc");
            var syntheticExpression = (Expression <Func <Document, IEnumerable <TIndex> > >)Expression.Lambda(
                typeof(Func <Document, IEnumerable <TIndex> >),
                Expression.Property(parameter, syntheticProperty),
                parameter);

            TIndex alias = default(TIndex);

            var join = BindDocument().JoinQueryOver(syntheticExpression, () => alias);

            _joins.Add(name, join);

            return(join);
        }
            public void Override(AutoMapping <TItemRecord> mapping)
            {
                // public TPartRecord TPartRecord {get;set;}
                var name              = typeof(TPartRecord).Name;
                var dynamicMethod     = new DynamicMethod(name, typeof(TPartRecord), null, typeof(TItemRecord));
                var syntheticMethod   = new SyntheticMethodInfo(dynamicMethod, typeof(TItemRecord));
                var syntheticProperty = new SyntheticPropertyInfo(syntheticMethod);

                // record => record.TPartRecord
                var parameter           = Expression.Parameter(typeof(TItemRecord), "record");
                var syntheticExpression = (Expression <Func <TItemRecord, TPartRecord> >)Expression.Lambda(
                    typeof(Func <TItemRecord, TPartRecord>),
                    Expression.Property(parameter, syntheticProperty),
                    parameter);

                mapping.References(syntheticExpression)
                .Access.NoOp()
                .Column("Id")
                .ForeignKey("none")     // prevent foreign key constraint from ContentItem(Version)Record to TPartRecord
                .Unique()
                .Not.Insert()
                .Not.Update()
                .Cascade.All();
            }