Hi,

I get below error:

Unable to cast object of type 'System.String' to type
'System.Collections.Generic.IEnumerable`1[NCommon.Controllers.Tags.ViewModels.TagSummary]

when i execute following query:

var list = (from item in items
                        select
                            new ItemSummary
                            {
                                Id = item.Id,
                                OffersCount = item.OfferCount(),
                                Title = item.Title,
                                UserId = item.User.Id,
                                UserUserName = item.User.UserName,
                                ViewCount = item.ViewCount,
                                Tags = (from t in item.Tags select new
TagSummary{Name = t.Name}).ToList()
                            })

The problem occures when Tags collection is being generated.

for a workaround, i handle this with following code block

            foreach (var itemSummary in list)
            {
                itemSummary.Tags = (from t in
TagTasks.GetAll().Where(t => t.Items.Any(x => x.Id == itemSummary.Id))
                                    select new TagSummary
                                    {
                                        Name = t.Name
                                    }).ToList();
            }


Here is the mapping part for Tags in item mapping:

                HasManyToMany(x => x.Tags)
                .Table("ItemsToTags")
                .Schema("dbo")
                .LazyLoad()
                .AsBag();

and here is the mapping part for Item in tag mapping:

        HasManyToMany(x => x.Items)
                .Table("ItemsToTags")
                .Schema("dbo")
                .LazyLoad()
                .AsBag().Inverse();

Any idea where the problem is or is this just a bug?

-- 
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.

Reply via email to