You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2007/02/22 22:33:09 UTC
svn commit: r510654 - in /ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test:
./ Domain/ Maps/MSSQL/SqlClient/ NUnit/SqlMapTests/ Scripts/MSSQL/
Author: gbayon
Date: Thu Feb 22 13:33:08 2007
New Revision: 510654
URL: http://svn.apache.org/viewvc?view=rev&rev=510654
Log:
- Added unit test
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-init.sql
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-schema.sql
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs Thu Feb 22 13:33:08 2007
@@ -0,0 +1,20 @@
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class Address
+ {
+ private int id;
+ public int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ private string street;
+ public string Street
+ {
+ get { return street; }
+ set { street = value; }
+ }
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Address.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs Thu Feb 22 13:33:08 2007
@@ -0,0 +1,47 @@
+#if dotnet2
+using System.Collections.Generic;
+#endif
+using System.Collections;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class Application
+ {
+ private int id;
+ public int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ private string name;
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+
+ private Role role;
+ public Role DefaultRole
+ {
+ get { return role; }
+ set { role = value; }
+ }
+
+#if dotnet2
+ private IList<ApplicationUser> users;
+ public IList<ApplicationUser> Users
+ {
+ get { return users; }
+ set { users = value; }
+ }
+#else
+ private IList users;
+ public IList Users
+ {
+ get { return users; }
+ set { roles = users; }
+ }
+#endif
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Application.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs Thu Feb 22 13:33:08 2007
@@ -0,0 +1,20 @@
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class Role
+ {
+ private int id;
+ public int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ private string name;
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Role.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs Thu Feb 22 13:33:08 2007
@@ -0,0 +1,54 @@
+#if dotnet2
+using System.Collections.Generic;
+#endif
+using System.Collections;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class ApplicationUser
+ {
+ private int id;
+ public int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ private string name;
+ public string UserName
+ {
+ get { return name; }
+ set { name = value; }
+ }
+
+ private Address address;
+ public Address Address
+ {
+ get { return address; }
+ set { address = value; }
+ }
+
+ private bool isActive;
+ public bool IsActive
+ {
+ get { return isActive; }
+ set { isActive = value; }
+ }
+
+#if dotnet2
+ private IList<Role> roles;
+ public IList<Role> Roles
+ {
+ get { return roles; }
+ set { roles = value; }
+ }
+#else
+ private IList roles;
+ public IList Roles
+ {
+ get { return roles; }
+ set { roles = value; }
+ }
+#endif
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj?view=diff&rev=510654&r1=510653&r2=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj Thu Feb 22 13:33:08 2007
@@ -109,6 +109,8 @@
<Compile Include="Domain\AccountCollection.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Domain\Address.cs" />
+ <Compile Include="Domain\Application.cs" />
<Compile Include="Domain\B.cs">
<SubType>Code</SubType>
</Compile>
@@ -182,6 +184,7 @@
<Compile Include="Domain\Petshop\Product.cs" />
<Compile Include="Domain\Product.cs" />
<Compile Include="Domain\Query.cs" />
+ <Compile Include="Domain\Role.cs" />
<Compile Include="Domain\Sample.cs">
<SubType>Code</SubType>
</Compile>
@@ -189,6 +192,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Domain\Simple.cs" />
+ <Compile Include="Domain\User.cs" />
<Compile Include="Domain\VarcharCallBack.cs" />
<Compile Include="NUnit\SqlMapTests\BaseTest.cs">
<SubType>Code</SubType>
@@ -426,6 +430,8 @@
<Content Include="Scripts\MSSQL\embed-param-setup-init.sql" />
<Content Include="Scripts\MSSQL\embed-param-test-init.sql" />
<Content Include="Scripts\MSSQL\enumeration-init.sql" />
+ <Content Include="Scripts\MSSQL\groupby-init.sql" />
+ <Content Include="Scripts\MSSQL\groupby-schema.sql" />
<Content Include="Scripts\MSSQL\line-item-init.sql" />
<Content Include="Scripts\MSSQL\more-account-records.sql" />
<Content Include="Scripts\MSSQL\Nullable-init.sql" />
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml?view=diff&rev=510654&r1=510653&r2=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/GroupByMapping.xml Thu Feb 22 13:33:08 2007
@@ -7,6 +7,11 @@
<typeAlias alias="NCategory" type="IBatisNet.DataMapper.Test.Domain.Petshop.Category, IBatisNet.DataMapper.Test"/>
<typeAlias alias="NProduct" type="IBatisNet.DataMapper.Test.Domain.Petshop.Product, IBatisNet.DataMapper.Test"/>
<typeAlias alias="NItem" type="IBatisNet.DataMapper.Test.Domain.Petshop.Item, IBatisNet.DataMapper.Test"/>
+ <typeAlias alias="Application" type="IBatisNet.DataMapper.Test.Domain.Application, IBatisNet.DataMapper.Test"/>
+ <typeAlias alias="ApplicationUser" type="IBatisNet.DataMapper.Test.Domain.ApplicationUser, IBatisNet.DataMapper.Test"/>
+ <typeAlias alias="Role" type="IBatisNet.DataMapper.Test.Domain.Role, IBatisNet.DataMapper.Test"/>
+ <typeAlias alias="Address" type="IBatisNet.DataMapper.Test.Domain.Address, IBatisNet.DataMapper.Test"/>
+
</alias>
<resultMaps>
@@ -69,10 +74,62 @@
<result property="Id" column="Product_Id"/>
<result property="Name" column="Product_Name" />
</resultMap>
+
+ <resultMap id="ApplicationResultMap" class="Application" groupBy="Id">
+ <result property="Id" column="ApplicationId"/>
+ <result property="Name" column="ApplicationName"/>
+ <result property="DefaultRole" resultMapping="GroupByMapping.DefaultRoleResultMap"/>
+ <result property="Users" resultMapping="GroupByMapping.ApplicationUserResultMap"/>
+ </resultMap>
+
+ <resultMap id="ApplicationUserResultMap" class="ApplicationUser" groupBy="Id">
+ <result property="Id" column="UserId"/>
+ <result property="UserName" column="UserName"/>
+ <result property="Address" resultMapping="GroupByMapping.AddressResultMap"/>
+ <result property="IsActive" column="ActiveFlag"/>
+ <result property="Roles" resultMapping="GroupByMapping.RoleResultMap"/>
+ </resultMap>
+
+ <resultMap id="DefaultRoleResultMap" class="Role" >
+ <result property="Id" column="DefaultRoleId"/>
+ <result property="Name" column="DefaultRoleName"/>
+ </resultMap>
+
+ <resultMap id="RoleResultMap" class="Role" >
+ <result property="Id" column="RoleId"/>
+ <result property="Name" column="RoleName"/>
+ </resultMap>
+
+ <resultMap id="AddressResultMap" class="Address" >
+ <result property="Id" column="AddressId"/>
+ </resultMap>
</resultMaps>
<statements>
+
+ <select id="GroupByBobHanson" resultMap="ApplicationResultMap" >
+ SELECT
+ Applications.ApplicationId, Applications.ApplicationName,
+ DefaultRole.RoleId as DefaultRoleId, DefaultRole.RoleName as DefaultRoleName,
+ Users.UserId, Users.UserName,
+ Addresses.AddressId,
+ ApplicationUsers.ActiveFlag,
+ Roles.RoleId, Roles.RoleName
+ FROM Applications
+ INNER JOIN Roles DefaultRole
+ ON DefaultRole.RoleId = Applications.DefaultRoleId
+ INNER JOIN ApplicationUserRoles
+ ON ApplicationUserRoles.ApplicationId = Applications.ApplicationId
+ INNER JOIN ApplicationUsers
+ ON ApplicationUsers.ApplicationId = ApplicationUserRoles.ApplicationId AND ApplicationUsers.UserId = ApplicationUserRoles.UserId
+ INNER JOIN Users ON Users.UserId = ApplicationUsers.UserId
+ LEFT JOIN Addresses
+ ON Addresses.AddressId = Users.AddressId
+ INNER JOIN Roles Roles
+ ON Roles.RoleId = ApplicationUserRoles.RoleId
+ WHERE Applications.ApplicationName = 'Application Manager'
+ </select>
<select id="GetCategories" resultMap="Category-Result" >
SELECT
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs?view=diff&rev=510654&r1=510653&r2=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs Thu Feb 22 13:33:08 2007
@@ -41,6 +41,32 @@
}
#endregion
+#if dotnet2
+ [Test]
+ public void TestBobHanson ()
+ {
+ InitScript(sqlMap.DataSource, ScriptDirectory + "groupby-schema.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "groupby-init.sql");
+
+ IList<Application> list = sqlMap.QueryForList<Application>("GroupByBobHanson", null);
+ Assert.AreEqual(1, list.Count);
+ Application application = list[0];
+
+ Assert.AreEqual("Admin", application.DefaultRole.Name);
+ Assert.AreEqual(2, application.Users.Count);
+ Assert.AreEqual("user1", application.Users[0].UserName);
+ Assert.IsNull(application.Users[0].Address);
+
+ Assert.AreEqual(1, application.Users[0].Roles.Count);
+ Assert.AreEqual("User", application.Users[0].Roles[0].Name);
+
+ Assert.AreEqual(2, application.Users[1].Roles.Count);
+ Assert.AreEqual("User", application.Users[1].Roles[1].Name);
+ Assert.AreEqual("Admin", application.Users[1].Roles[0].Name);
+
+ }
+#endif
+
[Test]
public void TestGroupByWithNullSon()
{
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-init.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-init.sql?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-init.sql (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-init.sql Thu Feb 22 13:33:08 2007
@@ -0,0 +1,25 @@
+
+INSERT INTO [Users]([UserId], [UserName], [AddressId])
+VALUES(1,'user1',null)
+INSERT INTO [Users]([UserId], [UserName], [AddressId])
+VALUES(14,'user14',null)
+
+INSERT INTO [Roles ]([RoleId], [RoleName])
+VALUES(1,'Admin');
+INSERT INTO [Roles ]([RoleId], [RoleName])
+VALUES(2,'User');
+
+INSERT INTO [Applications]([ApplicationId], [ApplicationName], [DefaultRoleId])
+VALUES(1, 'Application Manager', 1);
+
+INSERT INTO [ApplicationUserRoles]([ApplicationId], [UserId], [RoleId])
+VALUES(1,1,2);
+INSERT INTO [ApplicationUserRoles]([ApplicationId], [UserId], [RoleId])
+VALUES(1,14,1);
+INSERT INTO [ApplicationUserRoles]([ApplicationId], [UserId], [RoleId])
+VALUES(1,14,2);
+
+INSERT INTO [ApplicationUsers]([ApplicationId], [UserId], [ActiveFlag])
+VALUES(1,1,1);
+INSERT INTO [ApplicationUsers]([ApplicationId], [UserId], [ActiveFlag])
+VALUES(1,14,1);
\ No newline at end of file
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-schema.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-schema.sql?view=auto&rev=510654
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-schema.sql (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/groupby-schema.sql Thu Feb 22 13:33:08 2007
@@ -0,0 +1,174 @@
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_User_Address]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[Users] DROP CONSTRAINT FK_User_Address
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ApplicationUserRoles_Application]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[ApplicationUserRoles] DROP CONSTRAINT FK_ApplicationUserRoles_Application
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ApplicationUsers_Application]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[ApplicationUsers] DROP CONSTRAINT FK_ApplicationUsers_Application
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Application_Role]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[Applications] DROP CONSTRAINT FK_Application_Role
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ApplicationUserRoles_Role]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[ApplicationUserRoles] DROP CONSTRAINT FK_ApplicationUserRoles_Role
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ApplicationUserRoles_User]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[ApplicationUserRoles] DROP CONSTRAINT FK_ApplicationUserRoles_User
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ApplicationUsers_User]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ALTER TABLE [dbo].[ApplicationUsers] DROP CONSTRAINT FK_ApplicationUsers_User
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Addresses]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[Addresses]
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ApplicationUserRoles]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[ApplicationUserRoles]
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ApplicationUsers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[ApplicationUsers]
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Applications]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[Applications]
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Roles ]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[Roles ]
+
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Users]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+drop table [dbo].[Users]
+
+
+CREATE TABLE [dbo].[Addresses] (
+ [AddressId] [int] NOT NULL ,
+ [Street] [varchar] (50) COLLATE Latin1_General_CI_AS NULL
+) ON [PRIMARY]
+
+
+CREATE TABLE [dbo].[ApplicationUserRoles] (
+ [ApplicationId] [int] NULL ,
+ [UserId] [int] NULL ,
+ [RoleId] [int] NULL
+) ON [PRIMARY]
+
+
+CREATE TABLE [dbo].[ApplicationUsers] (
+ [ApplicationId] [int] NULL ,
+ [UserId] [int] NULL ,
+ [ActiveFlag] [bit] NULL
+) ON [PRIMARY]
+
+
+CREATE TABLE [dbo].[Applications] (
+ [ApplicationId] [int] NOT NULL ,
+ [ApplicationName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
+ [DefaultRoleId] [int] NULL
+) ON [PRIMARY]
+
+
+CREATE TABLE [dbo].[Roles ] (
+ [RoleId] [int] NOT NULL ,
+ [RoleName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL
+) ON [PRIMARY]
+
+
+CREATE TABLE [dbo].[Users] (
+ [UserId] [int] NOT NULL ,
+ [UserName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
+ [AddressId] [int] NULL
+) ON [PRIMARY]
+
+
+ALTER TABLE [dbo].[Addresses] WITH NOCHECK ADD
+ CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED
+ (
+ [AddressId]
+ ) ON [PRIMARY]
+
+
+ALTER TABLE [dbo].[Applications] WITH NOCHECK ADD
+ CONSTRAINT [PK_Application] PRIMARY KEY CLUSTERED
+ (
+ [ApplicationId]
+ ) ON [PRIMARY]
+
+
+ALTER TABLE [dbo].[Roles ] WITH NOCHECK ADD
+ CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED
+ (
+ [RoleId]
+ ) ON [PRIMARY]
+
+
+ALTER TABLE [dbo].[Users] WITH NOCHECK ADD
+ CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
+ (
+ [UserId]
+ ) ON [PRIMARY]
+
+
+ALTER TABLE [dbo].[ApplicationUserRoles] ADD
+ CONSTRAINT [FK_ApplicationUserRoles_Application] FOREIGN KEY
+ (
+ [ApplicationId]
+ ) REFERENCES [dbo].[Applications] (
+ [ApplicationId]
+ ),
+ CONSTRAINT [FK_ApplicationUserRoles_Role] FOREIGN KEY
+ (
+ [RoleId]
+ ) REFERENCES [dbo].[Roles ] (
+ [RoleId]
+ ),
+ CONSTRAINT [FK_ApplicationUserRoles_User] FOREIGN KEY
+ (
+ [UserId]
+ ) REFERENCES [dbo].[Users] (
+ [UserId]
+ )
+
+
+ALTER TABLE [dbo].[ApplicationUsers] ADD
+ CONSTRAINT [FK_ApplicationUsers_Application] FOREIGN KEY
+ (
+ [ApplicationId]
+ ) REFERENCES [dbo].[Applications] (
+ [ApplicationId]
+ ),
+ CONSTRAINT [FK_ApplicationUsers_User] FOREIGN KEY
+ (
+ [UserId]
+ ) REFERENCES [dbo].[Users] (
+ [UserId]
+ )
+
+
+ALTER TABLE [dbo].[Applications] ADD
+ CONSTRAINT [FK_Application_Role] FOREIGN KEY
+ (
+ [DefaultRoleId]
+ ) REFERENCES [dbo].[Roles ] (
+ [RoleId]
+ )
+
+
+ALTER TABLE [dbo].[Users] ADD
+ CONSTRAINT [FK_User_Address] FOREIGN KEY
+ (
+ [AddressId]
+ ) REFERENCES [dbo].[Addresses] (
+ [AddressId]
+ )
+
+