as described here: http://community.codesmithtools.com/forums/t/10513.aspx
I can't get a join table ABs filled from the tables A and B
automatically.
Here's a copy of my previous message:
Here's my actual test sample doing this.
1- the database
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'accessrights')
EXEC sys.sp_executesql N'CREATE SCHEMA [accessrights] AUTHORIZATION
[myadminuser]'
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID
(N'[accessrights].[B]') AND type in (N'U'))
BEGIN
CREATE TABLE [accessrights].[B](
[Bid] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](10) NULL,
CONSTRAINT [PK_B] PRIMARY KEY CLUSTERED
(
[Bid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID
(N'[accessrights].[A]') AND type in (N'U'))
BEGIN
CREATE TABLE [accessrights].[A](
[Aid] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](10) NULL,
CONSTRAINT [PK_A] PRIMARY KEY CLUSTERED
(
[Aid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID
(N'[accessrights].[ABs]') AND type in (N'U'))
BEGIN
CREATE TABLE [accessrights].[ABs](
[Aid] [int] NOT NULL,
[Bid] [int] NOT NULL
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =
OBJECT_ID(N'[accessrights].[FK_AB_A]') AND parent_object_id = OBJECT_ID
(N'[accessrights].[ABs]'))
ALTER TABLE [accessrights].[ABs] WITH CHECK ADD CONSTRAINT [FK_AB_A]
FOREIGN KEY([Aid])
REFERENCES [accessrights].[A] ([Aid])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =
OBJECT_ID(N'[accessrights].[FK_AB_B]') AND parent_object_id = OBJECT_ID
(N'[accessrights].[ABs]'))
ALTER TABLE [accessrights].[ABs] WITH CHECK ADD CONSTRAINT [FK_AB_B]
FOREIGN KEY([Bid])
REFERENCES [accessrights].[B] ([Bid])
2- my hibernate.cfg.xml (set in copy always) :
<?xml version='1.0' encoding='utf-8'?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
<property name="connection.connection_string">Data
Source=mydatawsource;Initial Catalog=mycatalog;Persist Security
Info=True;User ID=myadminuser;Password=mypassword</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
<property name="show_sql">false</property>
<property
name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle</property>
<property name="use_outer_join">true</property>
<mapping assembly="ConsoleApplication1" />
</session-factory>
</hibernate-configuration>
<log4net>
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%m" />
</layout>
</appender>
<root>
<priority value="WARN" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>
3- the Program.cs file of my sample ConsoleApplication1 :
using System;
using ConsoleApplication1.BusinessObjects;
using ConsoleApplication1.ManagerObjects;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IManagerFactory mgrFactory = new ManagerFactory();
IAManager aMgr = mgrFactory.GetAManager();
IBManager bMgr = mgrFactory.GetBManager();
A a = new A();
a.Name = "a object";
B b = new B();
b.Name = "b object";
a.Bs.Add(b);
aMgr.Save(a);
Console.WriteLine("complete");
Console.ReadKey();
}
}
}
Problems..... when I save A, it saves B also.... but nothing in ABs
table.
Any idea?
--
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.