What do you mean "You should manage the serialization of your
entities"? You mean to create a special class for compatibility with
JsonResult (ASP.NET MVC). Then, copy the properties from the populated
model class by NHibernate to the properties in the special class?
Another question, when querying by foreign column from the parent. How
do I tell NHibernate not to do a join with the other table, when all
I'm doing getting the rows by WHERE clause with the foreign column
(containing the id)??
/// <summary>Get items by category (list).</summary>
public static IList<Models.ListItem> GetItems(Guid categoryId) {
return Models.ListItem.FindAll(new ICriterion[] {
Restrictions.And(
Restrictions.Eq("itemList.listId", categoryId),
Restrictions.Eq("itemIsDeleted", false)
)
});
}
Sincerely,
William Chang
On Aug 10, 1:56 pm, Fabio Maulo <[email protected]> wrote:
> A circular reference was detected while serializing an object of type
> JsonResult"
> External issue. You should manage the serialization of your entities NH does
> not have nothing to do with it.
>
> 2009/8/10 William Chang <[email protected]>
>
>
>
>
>
>
>
> > I have two entities, "List" and "ListItem". My "List" entity have a
> > parent property: "public virtual List listParent {get;set;}". My
> > queries works when "listParent" is null, but when I set a parent for
> > example, "Countries" parent list, and the child list is "States". When
> > I do a query on "ListItem" to pulls items for "States" I got an error:
> > "A circular reference was detected while serializing an object of type
> > JsonResult".
>
> > What I found during debugging causing the error:
> > I did a query on the "ListItem" to pull all the items, but I want only
> > from the "States", so I need to tell NHibernate to do a "WHERE clause"
> > with the "listId" column. The nature of NHibernate, it queries the
> > "List" table for "States" and continue to query into the "listParent",
> > which I don't need.
>
> > 1. How do I limit the query to just the "listId" column in the "List"
> > table??? Because, the "List" table has a "listParent" column, which
> > NHibernate continue to query into.
> > 2. I don't know why NHibernate need to include the "List" table to do
> > a "WHERE clause" on the "listId", even though the "ListItem" table
> > already has a "listId" column???
>
> > Code Snippet:
> > /// <summary>Get items.</summary>
> > public static IList<Models.ListItem> GetItems(Guid categoryId) {
> > return Models.ListItem.FindAll(new ICriterion[] {
> > Restrictions.And(
> > Restrictions.Eq("itemList.listId", categoryId),
> > Restrictions.Eq("itemIsDeleted", false)
> > )
> > });
> > }
>
> > Specs:
> > NHibernate 2.1.0GA
> > Castle ActiveRecord 2.0
>
> > Thank you for your help,
> > William Chang
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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
-~----------~----~----~----~------~----~------~--~---