When the component is removed, NHibernate is incorrectly compared to NULL.

I have a problem updating the collection of components on the entity. It was originally mapped as a package, but this resulted in deleting and reinserting all entries every time. Change it to a group The problem is fixed, but a new problem is introduced.

The component type is called tracking. It has a composite key of UserID and ItemID and two nullable date attributes. When one of them creates a DateRead When set to the current time, later replace it with an entry with a new date.

The underlying SQL NHibernate generates a where clause to check whether all attributes match.

The problem is that another date of DateAcknowledged is usually null, and the generated SQL seems to have a syntax error. To perform a null check, perform this operation: = NULL instead of: IS NULL, as shown below:

DELETE FROM TrackingTable
WHERE ItemId ='a68f6dea-1c00-42e2-bc40-9fcf01121bd8' /* @p0 */
AND UserId ='c8aa41a4-e4c2-4347-ae6e- b48738a53b47' /* @p1 */
AND DateRead = '2012-01-26T12:56:46.00' /* @p2 */
AND DateAcknowledged = NULL /* @p3 */

The problem is that you don’t need two dates at all to determine what to delete. Just have a place to check the item ID and user ID.

This is the mapping code for my defined collection:< /p>

Set(x => x.Trackings,
mapper =>
{
mapper.Key(k => k.Column(" ItemId"));
mapper.Table("Tracking");
mapper.Access(Accessor.NoSetter);
},
collectionMapping => collectionMapping.Component(TrackingMap.Mapping()));

This is the mapping of components:

public class TrackingMap
{
public static Action> Mapping()
{
return c =>
{
c.ManyToOne(x => x.User , a => {a.Column("UserId"); a.ForeignKey("UserId"); });
c.Property(x => x.DateRead);
c.Property( x => x.DateAcknowledged, a => a.NotNullable(false));
};
}
}

Is there a way to tell NHibernate only where Use keys in sentences or compare null values ​​in the correct way?

7.2. This is explained in the Collections of dependent objects section, which states that this function is not supported :

Please note that a composite element mapping doesn’t support null-able properties if you’re using a . NHibernate has to use each columns value to identify a record when deleting objects (there is no separate primary key column in the composite element table), which is not possible with null values. You have to either use only not-null properties in a composite-element or choose a ,

, or .

I am having trouble updating the collection of components on the entity. It It was originally mapped as a package, but this resulted in all entries being deleted and reinserted each time. Changing it to a group fixed the problem, but introduced a new problem.

The component type says In order to track it has a composite key of UserID and ItemID and two nullable date attributes. When one of them is created DateRead is set to the current time, it will be replaced with an entry with a new date later.

The underlying SQL NHibernate generates a where clause to check whether all attributes match.

The problem is that another date of DateAcknowledged is usually null, and the generated SQL seems to have a syntax error, to execute null Check it to do this: = NULL instead of: IS NULL, as follows:

DELETE FROM TrackingTable
WHERE ItemId = ' a68f6dea-1c00-42e2-bc40-9fcf01121bd8' /* @p0 */
AND UserId ='c8aa41a4-e4c2-4347-ae6e-b48738a53b47' /* @p1 */
AND DateRead = '2012- 01-26T12:56:46.00' /* @p2 */
AND DateAcknowledged = NULL /* @p3 */

The problem is that you don’t need two dates at all to determine what to delete .You only need to have the location to check the project ID and user ID.

This is the mapping code for my defined set:

Set(x => x.Trackings,
mapper =>
{
mapper.Key(k => k.Column("ItemId"));
mapper.Table("Tracking");
mapper.Access(Accessor.NoSetter);
},
collectionMapping => collectionMapping.Component(TrackingMap.Mapping()));

This is the mapping of the component :

public class TrackingMap
{
public static Action> Mapping()
{
return c =>
{
c.ManyToOne(x => x.User, a => {a.Column("UserId"); a.ForeignKey("UserId"); });
c.Property(x => x.DateRead);
c.Property(x => x.DateAcknowledged, a => a.NotNullable(false));
};
}< br /> }

Is there a way to tell NHibernate to only use keys in the where clause or compare null values ​​in the correct way?

The section 7.2. Collections of dependent objects explains this, which states that this function is not supported:

< /p>

Please note that a composite element mapping doesn’t support null-able properties if you’re using a . NHibernate has to use each columns value to identify a record when deleting objects (there is no separate primary key column in the composite element table), which is not possible with null values. You have to either use only not-null properties in a composite-element or choose a ,

, or .

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4512 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.