ItemSelector problem with multiple web sites in same DB

Nov 21, 2007 at 10:29 AM
Edited Nov 21, 2007 at 10:29 AM
Hi,
I have multiple projects which uses same database.
They are completely different projects, with same classes names for example for StartPage but different implementation.
Everything works like a charm, but when I try to call popup for Items selection I always get an error, something like:
Object with id: 41 was not of the specified sublcass: N2.ContentItem (Discriminator was: 'Start Page')
I look at page with ID 41 and see that this is item from my other projects (I have root and start id 53&54 in new project).
It seems that ItemSelector go thought all items in databse, not hierarchically from rootID or stratpageID for the actual project and because class signatures are different the error is thrown.
When I export and import nodes to blank database it works ok but it's too expensive that I purchase new database on hosting provider for all project.
Am i right and do u know some quick fix for that?

Property definition for item selector is something like:

N2.Details.Editable("TARGET Url", typeof(ItemSelector), "Url", 95, ContainerName = "layout", Required = false)
public virtual string MenuTargetUrl

Thanks.
Coordinator
Nov 22, 2007 at 6:45 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Nov 22, 2007 at 6:59 PM
Interesting usage. The problem is that the find api bypass the tree hierarchy. I don't know of a good way to do hierarchical queries that works across databases.

I fixed this in the item selector pop up but the problem will remain in the search interface and if you use the find api.

I like the idea though. It might be an idea to add an extra site parameter to filter items at the database level.

Cheers/Cristian
Nov 22, 2007 at 8:13 PM
Can it be maked somehow with using ROOTID on find API. I think that Find can now be filtered root or I am wrong?

Thanks,
Dusan
Coordinator
Nov 22, 2007 at 8:58 PM
The problem is that before any filtering can take place nhibernate persistence will try to map the row from the database to a class in the application. If the class isn't found it will rightfully object and throw.

One workaround would be querying with types in but I would like to do this by default.
Nov 23, 2007 at 7:39 AM
What about to separate projects in same DB but in different tables, for example to set in web config table names for each project for n2Items, n2Details etc?
Will that be easier and doesn't it have consequences somewhere else?

BTW, is there some kind of functionality to define singleton objects for web site, for example .... one objects instance can be defined per web site like a contact form or site map or news container?

Thanks.

BTW, if I ask too much please tell me ;) .
Coordinator
Nov 24, 2007 at 12:05 AM

akrosoft wrote:
What about to separate projects in same DB but in different tables, for example to set in web config table names for each project for n2Items, n2Details etc?
Will that be easier and doesn't it have consequences somewhere else?


Nice idea. I just committed a change to the configuration builder to make it (somewhat) easier to define alternative mapping. To do it you'll need to:
  • copy the N2\Mappings\Default.hbm.xml to a project you control include it as an embedded resource
  • change the table definitions, e.g. <class name="..." table="n2Detail"> into <class name="..." table="someothertable">
  • configure the configuration builder to use this mapping instead of the default one:
<castle>
  <properties>...</properties>
  <include uri="assembly://N2/Engine/n2.configuration.xml"/>
  <components>
    <component id="n2.configurationBuilder">
      <parameters>
        <Properties>#{nhSettings}</Properties>
        <DefaultMapping>MyAssembly.Namespace.MyMapping.hbm.xml,MyAssembly</DefaultMapping>
      </parameters>
    </component>
</castle>


BTW, is there some kind of functionality to define singleton objects for web site, for example .... one objects instance can be defined per web site like a contact form or site map or news container?


I usually reference an item from the start or root node. Something along these lines (on the start page definition):
[EditableLink(...)]
public MySingletonSiteMapItem SiteMap
{
  get { return (MySingletonSiteMapItem)GetChild("sitemap") }
  set 
  { 
    value.Name = "sitemap"; 
    value.AddTo(this);
  }
}

And please ask =) Questions help me improve the documentation and ideas are always welcome.
Dec 3, 2007 at 10:33 AM
Work like a charm .... 10x