This question is locked. New answers and comments are not allowed.
Hi
NOTE: i don't use DomainDataSource to support the ItemsSource for the radgridview in my case(other cases, I always use domainDataSorce. And the behavior of the INSERT keyboard works nicely as your demo) . But if your solution use domainDataSource, then it is fine to me too.
I have 3 tables with the relationship(AND use Entity Framework with RIA service to retrieve the data by using the [Include] attribute)
Policy-PolicyYear : one to many
PolicyYear-PolicyDetail: one to many
My screen design will let the user input new Policy. Then after that they will input new PolicyYear for that policy. Then i will have a radgridview to let the user input PolicyDetails (as much as they want) for that new specific policyYear.
Then after pressing save, all of the related entity will be saved to the database accordingly.
This is my setup code
as you see that in the early state, the policyYear.PolicyDetails is an empty EntityCollection<PolicyDetail> because the policyYear has just been created. And policyYear.PolicyDetails collection will be filled out through the radgridview
(pictures included)
However, my problem is that When i press the INSERT keyboard, the radgridview always shows TWO new rows for the first time pressing Insert. The interesting thing is that if i type anything on the first new row, the second new row will be duplicated exactly the same values as the first rows.
And if i type anything on the second new rows , nothing will be stored if i press the saved button(and I WILL GET ERROR. Saying that "PolicyDetail has been editted and it needs to call the CommitEdit") ===> I try to call policydetailRadGridView.CommitEdit() but not helping at all.
I have included the XAML code for my screen and the code behind. And the SQL code if you want to reproduce the problem
My Web service on .web project (Note: i also use [Include] attribute)
and its MetaData files. Note: that i also use Include attribute
My SQL for creating those tables
NOTE: i don't use DomainDataSource to support the ItemsSource for the radgridview in my case(other cases, I always use domainDataSorce. And the behavior of the INSERT keyboard works nicely as your demo) . But if your solution use domainDataSource, then it is fine to me too.
I have 3 tables with the relationship(AND use Entity Framework with RIA service to retrieve the data by using the [Include] attribute)
Policy-PolicyYear : one to many
PolicyYear-PolicyDetail: one to many
My screen design will let the user input new Policy. Then after that they will input new PolicyYear for that policy. Then i will have a radgridview to let the user input PolicyDetails (as much as they want) for that new specific policyYear.
Then after pressing save, all of the related entity will be saved to the database accordingly.
This is my setup code
//Testing area : will be erased later policy = new Policy(); policyYear = new PolicyYear() { PolicyId = policy.PolicyId,EffectiveDate=DateTime.Now,ExpirationDate=DateTime.Now,CancelDate=DateTime.Now }; policyGrid.DataContext = policy; policyYearGrid.DataContext = policyYear; policyDetailRadGridView.ItemsSource = policyYear.PolicyDetails;(pictures included)
However, my problem is that When i press the INSERT keyboard, the radgridview always shows TWO new rows for the first time pressing Insert. The interesting thing is that if i type anything on the first new row, the second new row will be duplicated exactly the same values as the first rows.
And if i type anything on the second new rows , nothing will be stored if i press the saved button(and I WILL GET ERROR. Saying that "PolicyDetail has been editted and it needs to call the CommitEdit") ===> I try to call policydetailRadGridView.CommitEdit() but not helping at all.
I have included the XAML code for my screen and the code behind. And the SQL code if you want to reproduce the problem
<Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="93*" /> <RowDefinition Height="179*" /> <RowDefinition Height="234*" /> </Grid.RowDefinitions> <Grid Name="policyGrid"> <Grid.RowDefinitions> <RowDefinition Height="24*" /> <RowDefinition Height="30*" /> <RowDefinition Height="39*" /> </Grid.RowDefinitions> <sdk:Label Height="22" HorizontalAlignment="Left" Name="policyLB" VerticalAlignment="Top" Width="47" Content="Policy" /> <sdk:Label Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="-1,0,0,0" Name="policyCodeLB" VerticalAlignment="Top" Width="73" Content="Policy Code:" /> <TextBox Grid.Row="1" Height="23" Margin="96,0,0,0" Name="policyCodeTB" Text="{Binding PolicyCode,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True,ValidatesOnExceptions=True}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="76" /> <sdk:Label Content="Policy Desc:" Height="23" HorizontalAlignment="Left" Margin="241,0,0,0" Name="descriptionLB" VerticalAlignment="Top" Width="73" Grid.Row="1" /> <TextBox Height="23" Margin="352,0,0,0" Name="policyDescriptionTB" Text="{Binding PolicyDescription,Mode=TwoWay,ValidatesOnDataErrors=True,NotifyOnValidationError=True,ValidatesOnExceptions=True}" VerticalAlignment="Top" Grid.Row="1" HorizontalAlignment="Left" Width="76" /> <sdk:Label Content="Financial Dep:" Height="23" HorizontalAlignment="Left" Margin="-1,0,0,0" Name="fDepartmentLB" VerticalAlignment="Top" Width="85" Grid.Row="2" /> <TextBox Height="23" HorizontalAlignment="Left" Margin="96,0,0,0" Name="financialDepartmentTB" Text="{Binding FinancialDepartment, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True,ValidatesOnExceptions=True}" VerticalAlignment="Top" Width="76" Grid.Row="2" /> </Grid> <Grid Grid.Row="1" Name="policyYearGrid"> <Grid.RowDefinitions> <RowDefinition Height="25*" /> <RowDefinition Height="154*" /> </Grid.RowDefinitions> <sdk:Label Content="Policy Year" Height="22" HorizontalAlignment="Left" Name="policyYearLB" VerticalAlignment="Top" Width="72" /> <sdk:Label Content="Policy Year Code:" Height="22" HorizontalAlignment="Left" Margin="-1,0,0,0" Name="yearCodeLB" VerticalAlignment="Top" Width="101" Grid.Row="1" /> <TextBox KeyDown="policyYearCodeTB_KeyDown" TextChanged="policyYearCodeTB_TextChanged" Height="23" HorizontalAlignment="Left" Margin="96,0,0,0" Name="policyYearCodeTB" Text="{Binding PolicyYearCode, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" VerticalAlignment="Top" Width="76" Grid.Row="1" /> <sdk:Label Content="Agent Code:" Height="22" HorizontalAlignment="Left" Margin="-1,30,0,0" Name="agentCodeLB" VerticalAlignment="Top" Width="73" Grid.Row="1" /> <TextBox Height="23" HorizontalAlignment="Left" Margin="96,29,0,0" Name="agentCodeTB" Text="{Binding AgentCode, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True}" VerticalAlignment="Top" Width="76" Grid.Row="1" /> </Grid> <Grid Grid.Row="2" Name="policyDetailGrid"> <telerik:RadGridView Name="policyDetailRadGridView" AutoGenerateColumns="False" ActionOnLostFocus="CommitEdit" ShowGroupPanel="False" AddingNewDataItem="policyDetailRadGridView_AddingNewDataItem" DataLoadMode="Asynchronous" IsSynchronizedWithCurrentItem="false" > <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding AgentCommissionOverride, Mode=TwoWay}" Header="Agent Comm" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding PolicyDetailDescription, Mode=TwoWay}" Header="Description" /> <telerik:GridViewDataColumn Header="Eff Date" DataMemberBinding="{Binding EffectiveDate,Mode=TwoWay}" DataFormatString="{}{0:d}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid> </Grid>public partial class PolicyMaintenance : RadWindow { #region private members private PolicyMaintenanceContext policyMaintenance_ctx = new PolicyMaintenanceContext(); private PolicySearch policySearchScreen; private BusinessCodeSearchGrid businessCodeSearchGrid; private PolicyYearSearch policyYearSearch; // use this one so we won't load the Policy entities second time everytime we click on the search private bool isSearchPolicyLoaded = false; private bool hasConcurrencyIssue = false; private Policy policy; private PolicyYear policyYear; #endregion #region constructor public PolicyMaintenance() { InitializeComponent(); //Testing area : will be erased later policy = new Policy(); policyYear = new PolicyYear() { PolicyId = policy.PolicyId,EffectiveDate=DateTime.Now,ExpirationDate=DateTime.Now,CancelDate=DateTime.Now }; policyGrid.DataContext = policy; //Setup Data for PolicyYear Panel and PolicyYear radgridview SetUpYearAndDetail(); // } #endregion #region Setup Data for PolicyYear Panel and PolicyYear radgridview private void SetUpYearAndDetail() { policyYearGrid.DataContext = policyYear; policyDetailRadGridView.ItemsSource = policyYear.PolicyDetails; } #endregion
private void saveRBT_Click(object sender, RoutedEventArgs e) { policyDetailRadGridView.CommitEdit(); if (policy == null) { return; } if (policy.PolicyId == 0) { //check for the case the new policy already been added due to "Submit failed" case if (!policyMaintenance_ctx.Policies.Contains(policy)) { policyMaintenance_ctx.Policies.Add(policy); policy.PolicyYears.Add(policyYear); } } else { //for the case more PolicyYears has been added to the policy if (!policy.PolicyYears.Contains(policyYear)) { policy.PolicyYears.Add(policyYear); } } policyMaintenance_ctx.SubmitChanges(lo => { if (lo.HasError) { hasConcurrencyIssue = false; foreach (Entity entity in lo.EntitiesInError) { //Process entity conflict concurrency if (entity.EntityConflict != null) { hasConcurrencyIssue = true; MessageBox.Show("An update concurrency issue occur."); break; } } if (!hasConcurrencyIssue) { MessageBox.Show("save failed"); } lo.MarkErrorAsHandled(); } else { // active Add buttons addPolicyRBT.IsEnabled = true; addPolicyYearRBT.IsEnabled = true; MessageBox.Show("save successfully"); } }, null); } #region Adding/Edited/Delete event handler for policy detail radgridview private void policyDetailRadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e) { policyDetailRadGridView.CurrentColumn = this.policyDetailRadGridView.Columns[0]; var newPolicyDetail = new PolicyDetail() { PolicyYearId = policyYear.PolicyYearId, EffectiveDate = DateTime.Now }; policyYear.PolicyDetails.Add(newPolicyDetail); e.NewObject = newPolicyDetail; } #endregionMy Web service on .web project (Note: i also use [Include] attribute)
namespace SilverFinancials.Web.Services{ using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data; using System.Linq; using System.ServiceModel.DomainServices.EntityFramework; using System.ServiceModel.DomainServices.Hosting; using System.ServiceModel.DomainServices.Server; using SilverFinancials.Web.Models; // Implements application logic using the SilverFinancialsEntities context. // TODO: Add your application logic to these methods or in additional methods. // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access // Also consider adding roles to restrict access as appropriate. // [RequiresAuthentication] [EnableClientAccess()] public class PolicyMaintenanceService : LinqToEntitiesDomainService<SilverFinancialsEntities> { //////////////////////////////Extra Operation Services/////////////////////////////////// public IQueryable<PolicyYear> GetPolicyYearsByPolicyId(int policyId) { return this.ObjectContext.PolicyYears.Include("PolicyDetails").Where(p => p.PolicyId == policyId); } public IQueryable<PolicyDetail> GetPolicyDetailsByPolicyYearId(int policyYearId) { return this.ObjectContext.PolicyDetails.Where(p => p.PolicyYearId == policyYearId); } //Not used for now public PolicyYear GetPolicyYearByPolicyYearCode(int policyId, string policyYearCode) { return this.ObjectContext.PolicyYears.Include("PolicyDetails").Where(p => p.PolicyId == policyId && p.PolicyYearCode == policyYearCode).FirstOrDefault(); } // TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'Policies' query. public IQueryable<Policy> GetPolicies() { return this.ObjectContext.Policies.Include("PolicyYears").Include("PolicyYears.PolicyDetails"); } public void InsertPolicy(Policy policy) { if ((policy.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policy, EntityState.Added); } else { this.ObjectContext.Policies.AddObject(policy); } } public void UpdatePolicy(Policy currentPolicy) { this.ObjectContext.Policies.AttachAsModified(currentPolicy, this.ChangeSet.GetOriginal(currentPolicy)); } public void DeletePolicy(Policy policy) { if ((policy.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policy, EntityState.Deleted); } else { this.ObjectContext.Policies.Attach(policy); this.ObjectContext.Policies.DeleteObject(policy); } } // TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'PolicyDetails' query. public IQueryable<PolicyDetail> GetPolicyDetails() { return this.ObjectContext.PolicyDetails; } public void InsertPolicyDetail(PolicyDetail policyDetail) { if ((policyDetail.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policyDetail, EntityState.Added); } else { this.ObjectContext.PolicyDetails.AddObject(policyDetail); } } public void UpdatePolicyDetail(PolicyDetail currentPolicyDetail) { this.ObjectContext.PolicyDetails.AttachAsModified(currentPolicyDetail, this.ChangeSet.GetOriginal(currentPolicyDetail)); } public void DeletePolicyDetail(PolicyDetail policyDetail) { if ((policyDetail.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policyDetail, EntityState.Deleted); } else { this.ObjectContext.PolicyDetails.Attach(policyDetail); this.ObjectContext.PolicyDetails.DeleteObject(policyDetail); } } // TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'PolicyYears' query. public IQueryable<PolicyYear> GetPolicyYears() { return this.ObjectContext.PolicyYears; } public void InsertPolicyYear(PolicyYear policyYear) { if ((policyYear.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policyYear, EntityState.Added); } else { this.ObjectContext.PolicyYears.AddObject(policyYear); } } public void UpdatePolicyYear(PolicyYear currentPolicyYear) { this.ObjectContext.PolicyYears.AttachAsModified(currentPolicyYear, this.ChangeSet.GetOriginal(currentPolicyYear)); } public void DeletePolicyYear(PolicyYear policyYear) { if ((policyYear.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(policyYear, EntityState.Deleted); } else { this.ObjectContext.PolicyYears.Attach(policyYear); this.ObjectContext.PolicyYears.DeleteObject(policyYear); } } }}and its MetaData files. Note: that i also use Include attribute
namespace SilverFinancials.Web.Models{ using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data.Objects.DataClasses; using System.Linq; using System.ServiceModel.DomainServices.Hosting; using System.ServiceModel.DomainServices.Server; using SilverFinancials.Web.CustomValidators; // The MetadataTypeAttribute identifies PolicyMetadata as the class // that carries additional metadata for the Policy class. [MetadataTypeAttribute(typeof(Policy.PolicyMetadata))] public partial class Policy { // This class allows you to attach custom attributes to properties // of the Policy class. // // For example, the following marks the Xyz property as a // required property and specifies the format for valid values: // [Required] // [RegularExpression("[A-Z][A-Za-z0-9]*")] // [StringLength(32)] // public string Xyz { get; set; } internal sealed class PolicyMetadata { // Metadata classes are not meant to be instantiated. private PolicyMetadata() { } public string FinancialDepartment { get; set; } public string PolicyCode { get; set; } public string PolicyDescription { get; set; } public int PolicyId { get; set; } public PolicyType PolicyType { get; set; } public int PolicyTypeId { get; set; } [Include] public EntityCollection<PolicyYear> PolicyYears { get; set; } public Risk Risk { get; set; } public int RiskId { get; set; } public SubRisk SubRisk { get; set; } public int SubRiskId { get; set; } } } // The MetadataTypeAttribute identifies PolicyDetailMetadata as the class // that carries additional metadata for the PolicyDetail class. [MetadataTypeAttribute(typeof(PolicyDetail.PolicyDetailMetadata))] public partial class PolicyDetail { // This class allows you to attach custom attributes to properties // of the PolicyDetail class. // // For example, the following marks the Xyz property as a // required property and specifies the format for valid values: // [Required] // [RegularExpression("[A-Z][A-Za-z0-9]*")] // [StringLength(32)] // public string Xyz { get; set; } internal sealed class PolicyDetailMetadata { // Metadata classes are not meant to be instantiated. private PolicyDetailMetadata() { } public decimal AgentCommissionOverride { get; set; } public decimal AnnualPremium { get; set; } public int CommissionId { get; set; } public Coverage Coverage { get; set; } public int CoverageId { get; set; } public DateTime EffectiveDate { get; set; } public string PolicyDetailDescription { get; set; } public int PolicyDetailId { get; set; } public PolicyYear PolicyYear { get; set; } public int PolicyYearId { get; set; } public byte[] TableVersion { get; set; } public string TransactionTypeId { get; set; } public decimal WrittenPremium { get; set; } } } // The MetadataTypeAttribute identifies PolicyYearMetadata as the class // that carries additional metadata for the PolicyYear class. [MetadataTypeAttribute(typeof(PolicyYear.PolicyYearMetadata))] public partial class PolicyYear { // This class allows you to attach custom attributes to properties // of the PolicyYear class. // // For example, the following marks the Xyz property as a // required property and specifies the format for valid values: // [Required] // [RegularExpression("[A-Z][A-Za-z0-9]*")] // [StringLength(32)] // public string Xyz { get; set; } internal sealed class PolicyYearMetadata { // Metadata classes are not meant to be instantiated. private PolicyYearMetadata() { } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string AgentCode { get; set; } public BillType BillType { get; set; } public int BillTypeId { get; set; } public DateTime CancelDate { get; set; } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string CarrierCode { get; set; } public DateTime EffectiveDate { get; set; } public DateTime ExpirationDate { get; set; } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string FinanceCode { get; set; } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string InsuredCode { get; set; } public Policy Policy { get; set; } [Include] public EntityCollection<PolicyDetail> PolicyDetails { get; set; } public int PolicyId { get; set; } public PolicyStatu PolicyStatu { get; set; } public int PolicyStatusId { get; set; } public string PolicyYearCode { get; set; } public int PolicyYearId { get; set; } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string ProducerCode { get; set; } public byte[] TableVersion { get; set; } public Treaty Treaty { get; set; } public int TreatyId { get; set; } [CustomValidation(typeof(BusinessCodeForeignConstraintValidator), "DoesBusinessCodeExist")] public string UnderwriterCode { get; set; } } }}My SQL for creating those tables
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PolicyDetail_PolicyYearId]') AND parent_object_id = OBJECT_ID(N'[dbo].[PolicyDetail]'))ALTER TABLE [dbo].[PolicyDetail] DROP CONSTRAINT [FK_PolicyDetail_PolicyYearId]GOIF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PolicyYear_PolicyId]') AND parent_object_id = OBJECT_ID(N'[dbo].[PolicyYear]'))ALTER TABLE [dbo].[PolicyYear] DROP CONSTRAINT [FK_PolicyYear_PolicyId]GO/****** Object: Table [dbo].[PolicyDetail] Script Date: 11/19/2010 12:59:17 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PolicyDetail]') AND type in (N'U'))DROP TABLE [dbo].[PolicyDetail]GO/****** Object: Table [dbo].[PolicyDetail] Script Date: 11/19/2010 12:59:18 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[PolicyDetail]( [PolicyDetailId] [int] IDENTITY(1,1) NOT NULL, [PolicyYearId] [int] NOT NULL, [AgentCommissionOverride] [decimal](18, 2) NOT NULL, [PolicyDetailDescription] [varchar](60) NOT NULL, [EffectiveDate] [smalldatetime] NOT NULL, [TableVersion] [timestamp] NULL, CONSTRAINT [PK_PolicyDetail] PRIMARY KEY CLUSTERED ( [PolicyDetailId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[Policy] Script Date: 11/19/2010 13:59:36 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Policy]') AND type in (N'U'))DROP TABLE [dbo].[Policy]GO/****** Object: Table [dbo].[Policy] Script Date: 11/19/2010 13:59:36 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[Policy]( [PolicyId] [int] IDENTITY(1,1) NOT NULL, [PolicyCode] [varchar](30) NOT NULL, [PolicyDescription] [varchar](128) NOT NULL, [FinancialDepartment] [varchar](30) NOT NULL, CONSTRAINT [PK_Policy] PRIMARY KEY CLUSTERED ( [PolicyId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], CONSTRAINT [AK_Policy_PolicyNumber] UNIQUE NONCLUSTERED ( [PolicyCode] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGO/****** Object: Table [dbo].[PolicyYear] Script Date: 11/19/2010 14:05:04 ******/IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PolicyYear]') AND type in (N'U'))DROP TABLE [dbo].[PolicyYear]GO/****** Object: Table [dbo].[PolicyYear] Script Date: 11/19/2010 14:05:04 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[PolicyYear]( [PolicyYearId] [int] IDENTITY(1,1) NOT NULL, [PolicyId] [int] NOT NULL, [PolicyYearCode] [varchar](10) NOT NULL, [AgentCode] [varchar](15) NOT NULL, [TableVersion] [timestamp] NULL, CONSTRAINT [PK_PolicyYear] PRIMARY KEY CLUSTERED ( [PolicyYearId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[PolicyDetail] WITH CHECK ADD CONSTRAINT [FK_PolicyDetail_PolicyYearId] FOREIGN KEY([PolicyYearId])REFERENCES [dbo].[PolicyYear] ([PolicyYearId])GOALTER TABLE [dbo].[PolicyDetail] CHECK CONSTRAINT [FK_PolicyDetail_PolicyYearId]GOALTER TABLE [dbo].[PolicyYear] WITH CHECK ADD CONSTRAINT [FK_PolicyYear_PolicyId] FOREIGN KEY([PolicyId])REFERENCES [dbo].[Policy] ([PolicyId])GOALTER TABLE [dbo].[PolicyYear] CHECK CONSTRAINT [FK_PolicyYear_PolicyId]GO