NHibernate: как сопоставить один и тот же столбец с атрибутом и отношением

Я пытаюсь сопоставить один и тот же столбец как атрибут и отношение (по причинам, связанным с устаревшими данными), используя следующее сопоставление:

 References(x => x.BaseProductTemplate, "ProductCodeTxt");
 Map(x => x.DescriptionCode, "ProductCodeTxt")
                .CustomType(typeof(TrimmedStringUserType));

но «System.IndexOutOfRangeException: неверный индекс 9 для этой коллекции SqlParameterCollection со значением Count = 9». выбрасывается исключение. Как я могу добиться этого с помощью NH, не получая этой ошибки.

Вот класс:

    public static MarketingPlanBaseProduct Create(BaseProductTemplate baseProductTemplate, ProductType productType)
        {
            var toReturn = new MarketingPlanBaseProduct();

            toReturn.BaseProductTemplate = baseProductTemplate;
            toReturn.Type = productType;


            return toReturn;
        }

        protected MarketingPlanBaseProduct()
        {
            _coInsurancePercentages = new List<PlanCoInsurance>();
            _benefits = new List<BaseProductBenefit>();
        }


  #region " Old system workaround "

        /// HACK: In insight users were able to override description and the code, and system was displaying description from 
        /// the "BaseProduct" table, not from "ProductRef" table. In order to have this description display in Insight 
        /// during transitional period
        /// we are modeling the MarketingPlanBaseProduct with two independent properties 
        /// that will be loaded based on the values in "ProductCodeTxt" and ProductNameTxt.
        /// New MarketingPlanBaseProducts will however have description populated based on BaseProductTemplate ("ProductRef")
        /// and code/description will not be changable from New System
        /// Once old system is cut off, "DescriptionCode" Property should be removed,
        /// "Name should be changed to be mapped property that derives value from BaseProductTemplate relationship

        private string _descriptionCode;
        public virtual string DescriptionCode
        {
            get
            {
                return _descriptionCode;
            }
        }

        private string _name;
        public virtual string Name
        {
            get { return _name; }
        }

        private  void SetName(BaseProductTemplate baseProductTemplate)
        {
            _name = baseProductTemplate.Name;
            _descriptionCode = baseProductTemplate.Code;
        }

     private BaseProductTemplate _baseProductTemplate;
        public virtual BaseProductTemplate BaseProductTemplate
        {
            get
            {
                return _baseProductTemplate;
            }
            private set
            {
                _baseProductTemplate = value;
                SetName(_baseProductTemplate);
            }
        }

person epitka    schedule 10.03.2010    source источник
comment
Это отображение Fluent-NHibernate. Можете ли вы предоставить нам свою модель предметной области, чтобы мы могли лучше понять отношения, которые вы хотите здесь описать?   -  person Will Marcouiller    schedule 10.03.2010


Ответы (2)


Вы также можете использовать формулу:

Map(x => x.MyProperty).Formula("propertyColumn").Not.Insert().Not.Update();
person Stamppot    schedule 04.10.2012

Поскольку это было сопоставлено с представлением, я добавил в представление еще один столбец с другим именем, сопоставленным с одним и тем же столбцом, и это работает.

person epitka    schedule 10.03.2010