Компонент NHibernate, отображающийся - Пустой Компонент

https://developers.google.com/places/web-service/search#PlaceSearchRequests

Я думаю, что это ваш пункт назначения, используя этот API, вы можете найти близлежащие места, используя лат и радиус

12
задан 20 April 2009 в 14:44
поделиться

2 ответа

Я думаю, что это поведение по умолчанию для сопоставления компонентов. Документы NHibernate для компонента говорят, что если все элементы компонента имеют значение NULL, сам компонент будет иметь значение NULL.

Если у вас есть только одно свойство в компоненте, возможно, имеет смысл просто отобразить его как обнуляемый DateTime. свойство класса Matter.

10
ответ дан 26 October 2019 в 11:17
поделиться

I also ran into the same problem of expecting NHibernate to initialize my component even if all its members are null in the DB. My motivation behind this implementation was to move as much logic concerning my component into the component, not having to deal with it being null or not.

Thanks to this post my search for an explanation why my unit tests were failing for all null values inside the component was short. I fixed this piece in the puzzle by extending the auto-property of my component class ArrivalDay and assigning a fresh instance myself when null is assigned:

private ArrivalDay _arrivalDay;
public ArrivalDay ArrivalDay
{
    get { return _arrivalDay; }
    set { _arrivalDay = value ?? new ArrivalDay(); }
}

This works like a charm and means very little overhead on the containing class.

5
ответ дан 26 October 2019 в 11:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: