I have found the problem and it lies in the line of linq code below:
return PartialView("_List", this.noticiaRepository.GetMany(x => x.Id >=
0).OrderBy(x => x.FrontpagePosition ?? int.MaxValue).ThenByDescending(x =>
x.FechaAlta).Skip((page - 1) * itemsPerPage).Take(itemsPerPage));
If I remove that linq and just to a getall() it work with out problems... Any
thoughts?
On Tuesday, September 25, 2012 11:45:30 PM UTC+2, Fabricio Martinez wrote:
>
> Hello,
>
> I have just upgraded NHIbernate and Fluent to the latest versions (NH to
> 3.3.1.4000 and Fluent to 1.3.0.733) and my working solution has stop
> working with certain objects with the following error.
>
> {System.IndexOutOfRangeException: Invalid index 3 for this
> SqlParameterCollection with Count=3.
> at System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32 index)
> at System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32
> index)
> at
> System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32
>
> index)
> at NHibernate.Type.Int32Type.Set(IDbCommand rs, Object value, Int32
> index)
> at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object
> value, Int32 index)
> at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object
> value, Int32 index, ISessionImplementor session)
> at NHibernate.Param.NamedParameterSpecification.Bind(IDbCommand
> command, IList`1 multiSqlQueryParametersList, Int32
> singleSqlParametersOffset, IList`1 sqlQueryParametersList, QueryParameters
> queryParameters, ISessionImplementor session)
> at NHibernate.Param.NamedParameterSpecification.Bind(IDbCommand
> command, IList`1 sqlQueryParametersList, QueryParameters queryParameters,
> ISessionImplementor session)
> at NHibernate.SqlCommand.SqlCommandImpl.Bind(IDbCommand command,
> ISessionImplementor session)
> at NHibernate.Loader.Loader.PrepareQueryCommand(QueryParameters
> queryParameters, Boolean scroll, ISessionImplementor session)
> at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
> QueryParameters queryParameters, Boolean returnProxies)
> at
> NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor
>
> session, QueryParameters queryParameters, Boolean returnProxies)
> at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
> QueryParameters queryParameters)}
>
> What its weird to me is that this was working perfectly.
>
> The object is as follows.
>
> [DataContract(IsReference = true)]
> [KnownType(typeof(Categoria))]
> [KnownType(typeof(Comentario))]
> public partial class Noticia
> {
> [DataMember]
> public virtual long Id { get; set; }
>
> [DataMember]
> public virtual string Asunto { get; set; }
>
> [DataMember]
> public virtual string Intro { get; set; }
>
> [DataMember]
> public virtual string Texto { get; set; }
>
> [DataMember]
> public virtual bool Publicar { get; set; }
>
> [DataMember]
> public virtual Categoria Categoria { get; set; }
>
> [DataMember]
> public virtual Producto Producto { get; set; }
>
> [DataMember]
> public virtual Empresa Empresa { get; set; }
>
> [DataMember]
> public virtual IList<Comentario> Comentario { get; set; }
>
> [DataMember]
> public virtual bool Frontpage { get; set; }
>
> [DataMember]
> public virtual int? FrontpagePosition { get; set; }
>
> [DataMember]
> public virtual string Tags { get; set; }
>
> [DataMember]
> public virtual Usuario Creador { get; set; }
>
> [DataMember]
> public virtual DateTime FechaAlta { get; set; }
> }
>
> Mapping:
> public partial class NoticiaMap: ClassMap<Noticia>
> {
> public NoticiaMap()
> {
> //Table("NoticiaSet");
> Id(x => x.Id).GeneratedBy.Identity();
> HasMany(x => x.Comentario).LazyLoad().Inverse().Cascade.All();
> References(x => x.Categoria).Nullable();
> References(x => x.Empresa).Nullable();
> References(x => x.Producto).Nullable();
> Map(x => x.Publicar).Not.Nullable();
> Map(x => x.Asunto).Length(512).Not.Nullable();
> Map(x => x.Intro).Length(1024).Nullable();
> Map(x =>
> x.Texto).CustomType("StringClob").CustomSqlType("nvarchar(max)").Not.Nullable();
> Map(x => x.FechaAlta).Not.Nullable();
> Map(x => x.Frontpage).Not.Nullable().Default("0");
> Map(x => x.FrontpagePosition).Nullable();
> Map(x => x.Tags).Length(512).Nullable();
> References(x => x.Creador).Not.Nullable();
> }
> }
>
> Code Failing:
> @foreach (var item in Model)
> {
> <div class="row">
> <div style="text-align:center;" class="one
> columns">@item.Publicar.ToString()</div>
> <div style="text-align:center;" class="one
> columns">@item.Frontpage</div>
> <div style="text-align:center;" class="one
> columns">@item.FrontpagePosition</div>
> <div style="text-align:center;" class="three
> columns">@item.Asunto</div>
> <div style="text-align:center;" class="one
> columns">
> @if (item.Categoria != null) {
> @item.Categoria.Nombre }
> @if (item.Empresa != null) {
> @item.Empresa.Nombre }
> @if (item.Producto != null) {
> @item.Producto.Nombre }
> </div>
> <div style="text-align:center;" class="one
> columns">@item.Creador.Nombre</div>
> <div style="text-align:center;" class="one
> columns">@item.FechaAlta.ToShortDateString()</div>
> <div style="text-align:center;" class="three
> columns">
> <a href="#"
> onclick="javascript:SourceInjector('#Content', '@Url.Action("Modificar",
> "Noticia", new { id = item.Id })')">Modificar</a> ||
> @Ajax.ActionLink("Eliminar", "Eliminar",
> "Noticia", new { id = item.Id }, new AjaxOptions { Confirm = "¿Eliminar
> Noticia " + item.Asunto + "?", HttpMethod = "Post", UpdateTargetId =
> "Content" }, null) ||
> <a href="@Url.Action(item.Id.ToString(),
> "Articulo")" target="_blank">Preview</a>
> </div>
> </div>
> }
>
>
> As soon as it goes into the foreach it fails. What baffles me is that this
> was working before.
>
> Any help welcomed.
>
> -Cheers,
> Fabricio
>
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/F33L-mvSv0QJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.