SEBA | 25 Jun 17:13
Picon

Colección Vacía (Empty)


Hola. Les comento mi problema.

Tengo la siguiente clase:

public class ListaPrecios
    {
	...
	private IList<ListaPreciosItem> _items = new List<ListaPreciosItem>
();
	...
	public virtual IList<ListaPreciosItem> Items
        {
            get
            {
                return _items;
            }
            set { _items = value; }
        }
	...
}

El mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="SHGestionBO" namespace="SHGestionBO.Class" default-access
="nosetter.camelcase-underscore">
  <class name="ListaPrecios" table="ListaPrecios" lazy="false" dynamic-
update="true" optimistic-lock="all">
    <id name="NroLista" column="nro_lista" type ="int" >
      <generator class="assigned" />
    </id>
	...
    <bag name="Items" table="ListaPreciosItem"  inverse ="true"
cascade="all-delete-orphan" lazy="true" >
      <key column="nro_lista" />
      <one-to-many class="ListaPreciosItem" />
    </bag>
	...
  </class>
</hibernate-mapping>

En la capa de presentacion (WinForm) enlazo a una grilla el List
devuelto:

this.listaPreciosItemBindingSource.DataSource =
this.currentListaPrecios().Items;
//this.currentListaPrecios() devuelve un obj ListaPrecios

Al hacer debug de la linea anterior en el Visual Studio:
- Si creo un new Obj ListaPrecios, el value en el debug de
"this.currentListaPrecios().Items" me devuelve "Count = 0". PERFECTO.
Desde la grilla
puedo agregar nuevos obj ListaPreciosItem sin problemas.

-  al RECUPERAR un Obj ListaPrecios con un metodo Repositorio.getById
(), el value en el debug de "this.currentListaPrecios().Items" me
devuelve "{}" en lugar de "Count = 0".
Y al querer editar la grilla me devuelve el siguiente error:

System.ArgumentException was unhandled
  Message="El valor \"System.Object\" no es del tipo
\"SHGestionBO.Class.ListaPreciosItem\" y no se puede utilizar en esta
colección genérica.\r\nNombre del parámetro: value"
  Source="mscorlib"
  ParamName="value"
  StackTrace:
       en System.ThrowHelper.ThrowWrongValueTypeArgumentException
(Object value, Type targetType)
       en System.Collections.Generic.List`1.VerifyValueType(Object
value)
       en
System.Collections.Generic.List`1.System.Collections.IList.Add(Object
item)
       en NHibernate.Collection.PersistentBag.Add(Object value) en c:
\CSharp\NH\nhibernate\src\NHibernate\Collection\PersistentBag.cs:línea
379
       en System.Windows.Forms.BindingSource.Add(Object value)
       en System.Windows.Forms.BindingSource.AddNew()
       en System.Windows.Forms.CurrencyManager.AddNew()
       en
System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()
       en
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded
()
       en System.Windows.Forms.DataGridView.OnRowEnter
(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32
rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
       en System.Windows.Forms.DataGridView.SetCurrentCellAddressCore
(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress,
Boolean validateCurrentCell, Boolean throughMouseClick)
       en System.Windows.Forms.DataGridView.OnCellMouseDown
(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
       en System.Windows.Forms.DataGridView.OnCellMouseDown
(DataGridViewCellMouseEventArgs e)
       en System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs
e)
       en System.Windows.Forms.Control.WmMouseDown(Message& m,
MouseButtons button, Int32 clicks)
       en System.Windows.Forms.Control.WndProc(Message& m)
       en System.Windows.Forms.DataGridView.WndProc(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.OnMessage
(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.WndProc
(Message& m)
       en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW
(MSG& msg)
       en
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       en
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner
(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.ThreadContext.RunMessageLoop
(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.Run(Form mainForm)
       en SHGestionPresentacion.Program.Main() en C:\Documents and
Settings\shidalgo\Mis documentos\Visual Studio 2008\Projects\SHGestion
\SHGestionPresentacion\Program.cs:línea 29
       en System.AppDomain._nExecuteAssembly(Assembly assembly, String
[] args)
       en System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
       en
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       en System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
       en System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       en System.Threading.ThreadHelper.ThreadStart()
  InnerException:

El "{}" pense q era un null por lo q modifique el GET de la propiedad
para q si _items es null devuelva new List<ListaPreciosItem>().

Quería saber si hay alguna forma para q Nhibernate devuelva "Count =
0" (new List<ListaPreciosItem>()) y no un "{}".

Estoy utilizando NHibernate-2.1.0.Beta2.

Gracias.

--~--~---------~--~----~------------~-------~--~----~
Para escribir al Grupo, hágalo a esta dirección: NHibernate-Hispano <at> googlegroups.com
Para más, visite: http://groups.google.com/group/NHibernate-Hispano
-~----------~----~----~----~------~----~------~--~---


Gmane