Hola, disculpen los moleste con este asunto, se que hay muchísima información sobre él pero he probado mil cosas distintas y no he llegado a la solución
Copio mi código
La página de ejemplo que hice:
aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/LayoutNew.Master" AutoEventWireup="true" CodeBehind="Prueba.aspx.cs" Inherits="OfficeMart.Prueba" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v10.1, Version=10.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
</asp:Content>
El cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DomainLayer.Objects;
using System.Text;
using System.Configuration;
using NHibernate;
using System.Net.Mail;
using OfficeMart.DataAccesLayer;
namespace OfficeMart
{
public partial class Prueba : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ISession Sesion;
ITransaction Transaction = null;
Sesion = SessionManager.OpenSession();
Transaction = Sesion.BeginTransaction();
BO_User user = (BO_User)Sesion.Load(typeof(BO_User), Request["User"]);
user.Categorys.Clear();
try
{
Sesion.SaveOrUpdate(user);
Transaction.Commit();
}
catch (Exception er)
{
Transaction.Rollback();
Response.Redirect("ErrorPage.aspx?Error=" + er.Message);
}
finally
{
Sesion.Close();
Sesion.Dispose();
}
}
}
}
El cs para hibernate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DomainLayer.Objects
{
public class BO_User
{
public BO_User()
{ }
public BO_User(String UserName, String Password, String Name, String LastName, String Email, BO_Rol Rol, Boolean Enable, List<BO_CategoryUser> Categorys)
{
this.UserName = UserName;
this.Password = Password;
this.Name = Name;
this.LastName = LastName;
this.Email = Email;
this.Rol = Rol;
this.Enable = Enable;
this.Categorys = Categorys;
}
public String UserName { get; set; }
public String Password { get; set; }
public String Name { get; set; }
public String LastName { get; set; }
public String Email { get; set; }
public BO_Rol Rol { get; set; }
public Boolean Enable { get; set; }
public BO_Area Area { get; set; }
public BO_Company Company {get; set;}
public IList<BO_CategoryUser> Categorys { set; get; }
public override string ToString()
{
return this.LastName + ", " + this.Name + " - " + this.Rol.Description;
}
}
}
El xml para hibernate
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
<class name="BO_User" table="USERS" lazy="false">
<id name="UserName" column="USERNAME" type="string" >
<generator class="assigned" />
</id>
<property name="Password" column="PASSWORD" type="string" not-null="true"/>
<property name="Name" column="NAME" type="string" not-null="true"/>
<property name="LastName" column="LASTNAME" type="string" not-null="true"/>
<property name="Email" column="EMAIL" type="string" not-null="true"/>
<many-to-one name="Rol" column="IDROL" class="BO_Rol" />
<property name="Enable" column="ENABLE" type="boolean" not-null="true"/>
<many-to-one name="Company" column="IDCOMPANY" class="BO_Company" />
<many-to-one name="Area" column="IDAREA" class="BO_Area" />
<bag name="Categorys" cascade="all-delete-orphan">
<key column="USERNAME"/>
<one-to-many class="BO_CategoryUser"/>
</bag>
</class>
</hibernate-mapping>
El mensaje de error
deleted object would be re-saved by cascade (remove deleted object from associations): 100, of class: DomainLayer.Objects.BO_CategoryUser
Lo que necesito hacer es simplemente eliminar la relación entre el usuario (BO_User) y las categorías BO_CategoryUser
Estoy usando esta tabla en el medio para relacionar usuarios con categorías
Este es el código del cs de la tabla
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DomainLayer.Objects
{
public class BO_CategoryUser
{
public BO_CategoryUser()
{ }
public BO_CategoryUser(Int32 IdCategoryUser, BO_Category Category, BO_User User)
{
this.IdCategoryUser = IdCategoryUser;
this.Category = Category;
this.User = User;
}
public Int32 IdCategoryUser { get; set; }
public BO_Category Category { get; set; }
public BO_User User { get; set; }
}
}
Y este el xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainLayer" namespace="DomainLayer.Objects" default-lazy="false">
<class name="BO_CategoryUser" table="CATEGORY_USER" lazy="false">
<id name="IdCategoryUser" column ="IDCATEGORYUSER" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<many-to-one name="Category" column="IDCATEGORY" class="BO_Category" />
<many-to-one name="User" column="USERNAME" class="BO_User" />
</class>
</hibernate-mapping>
Desde ya muchas gracias.