I am getting an error in my one of tables, "Relationship", I building a model using code first with a relationship being build in the model to several other models. I have different names being in the relational Models. The error is as follows:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Relationships_dbo.Surnames_FaSurname". The conflict occurred in database "C:\FAMILYSHOWSOURCE\MVCTEST\MVCNOK\MVCNOK\APP_DATA\MVCTEST.MDF", table "dbo.Surnames", column 'SurnameId'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Relationships_dbo.Surnames_FaSurname". The conflict occurred in database "C:\FAMILYSHOWSOURCE\MVCTEST\MVCNOK\MVCNOK\APP_DATA\MVCTEST.MDF", table "dbo.Surnames", column 'SurnameId'.
The statement has been terminated.
Source Error:
Line 417: {
Line 418: db.Relationships.Add(relationship);
Line 419: db.SaveChanges();
Line 420: return RedirectToAction("Index");
Line 421: }
Source File: C:\familyshowsource\MvcTest\MvcNOK\MvcNOK\Controllers\RelationshipsController.cs Line: 419
Stack Trace:
[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Relationships_dbo.Surnames_FaSurname". The conflict occurred in database "C:\FAMILYSHOWSOURCE\MVCTEST\MVCNOK\MVCNOK\APP_DATA\MVCTEST.MDF", table "dbo.Surnames", column 'SurnameId'.
The statement has been terminated.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2440274
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5765240
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4169
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) +409
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2127
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +911
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +64
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c) +14
System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +402
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +166
System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +12
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) +234
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +159
[UpdateException: An error occurred while updating the entries. See the inner exception for details.]
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +329
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +11
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction) +132
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() +106
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() +13
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +288
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) +157
System.Data.Entity.Core.Objects.<>c__DisplayClass2a.<SaveChangesInternal>b__27() +25
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +162
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) +221
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +11
System.Data.Entity.Internal.InternalContext.SaveChanges() +113
[DbUpdateException: An error occurred while updating the entries. See the inner exception for details.]
System.Data.Entity.Internal.InternalContext.SaveChanges() +191
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +27
System.Data.Entity.DbContext.SaveChanges() +22
MvcNOK.Controllers.RelationshipsController.Create(Relationship relationship) in C:\familyshowsource\MvcTest\MvcNOK\MvcNOK\Controllers\RelationshipsController.cs:419
lambda_method(Closure , ControllerBase , Object[] ) +103
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987157
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
The main model, "Relationship", code is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace MvcNOK.Models
{
public class Relationship
{
[Key]
public int RelationshipId { get; set; }
[Required]
[Display(Name = "Letter of Family ")]
public int FaSurname { get; set; }
[Required]
[Display(Name = "Family Tree Name")]
public int RFamilie { get; set; }
[Required]
[Display(Name = "Letter of First Person Relationship")]
public int FAlphabet { get; set; }
[Required]
[Display(Name = "Surname of First Person Relationship")]
public int FSurname { get; set; }
[Required]
[Display(Name = "First Person Relationship")]
public int FIndividual { get; set; }
[Required]
[Display(Name = "Kinship of First Person")]
public int FKinship { get; set; }
[Required]
[Display(Name = "First Person Role in Kinship")]
public int FRole { get; set; }
[Required]
[Display(Name = "Letter of Second Person Relationship")]
public int SAlphabet { get; set; }
[Required]
[Display(Name = "Surname of Second Person Relationship")]
public int SSurname { get; set; }
[Required]
[Display(Name = "Second Person Relationship")]
public int SIndividual { get; set; }
[Required]
[Display(Name = "Kinship of Second Person")]
public int SKinship { get; set; }
[Required]
[Display(Name = "Second Person Role in Kinship")]
public int SRole { get; set; }
[Required]
[Display(Name = "Start of Relationship")]
public string Start { get; set; }
[Required]
[Display(Name = "Era of Start of Relationship")]
public int EraId { get; set; }
[Required]
[Display(Name = "Main Country that Relationship started")]
public int NCountrie { get; set; }
[Required]
[Display(Name = "Country that Relationship started")]
public int Countrie { get; set; }
[Required]
[Display(Name = "State that Relationship started")]
public int State { get; set; }
[Required]
[Display(Name = "City that Relationship started")]
public int Citie { get; set; }
[Required]
[Display(Name = "Source of start of Relationship")]
public string Source { get; set; }
[Display(Name = "Source Notes of Start of Relationship")]
public string Notes { get; set; }
[Required]
[Display(Name = "End of Relationship")]
public string End { get; set; }
[Required]
[Display(Name = "Era of End of Relationship")]
public int DEraId { get; set; }
[Required]
[Display(Name = "Main Country that Relationship ended")]
public int NDcountrie { get; set; }
[Required]
[Display(Name = "Country that Relationship ended")]
public int DCountrie { get; set; }
[Required]
[Display(Name = "State that Relationship ended")]
public int DState { get; set; }
[Required]
[Display(Name = "City that Relationship ended")]
public int DCitie { get; set; }
[Required]
[Display(Name = "Source of end of Relationship")]
public string ESource { get; set; }
[Display(Name = "Source Notes of end of Relationship")]
public string ENotes { get; set; }
public virtual Surname FamilieSurnames { get; set; }
public virtual Familie RelationshipFamilies { get; set; }
public virtual Alphabet FirstAlphabets { get; set; }
public virtual Surname FirstSurnames { get; set; }
public virtual Individual FirstIndividuals { get; set; }
public virtual Kinship FirstKinships { get; set; }
public virtual KRole FirstRoles { get; set; }
public virtual Alphabet SecondAlphabets { get; set; }
public virtual Surname SecondSurnames { get; set; }
public virtual Individual SecondIndividuals { get; set; }
public virtual Kinship SecondKinships { get; set; }
public virtual KRole SecondRoles { get; set; }
public virtual Era Eras { get; set; }
public virtual NCountrie NCountries { get; set; }
public virtual Countrie Countries { get; set; }
public virtual State States { get; set; }
public virtual Citie Cities { get; set; }
public virtual DEra DEras { get; set; }
public virtual NDcountrie NDcountries { get; set; }
public virtual DCountrie DCountries { get; set; }
public virtual DState DStates { get; set; }
public virtual DCitie DCities { get; set; }
}
}
There are several other Models that Relate to this model, "Relationship", the first one being "Surname". They are as follow:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Web;
namespace MvcNOK.Models
{
public class Surname
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
[Key]
public int SurnameId { get; set; }
public int AlphabetId { get; set; }
[Required]
[Display(Name = "Surname")]
public string Name { get; set; }
[Required]
[Display(Name = "Description")]
public string Description { get; set; }
public byte[] InternalImage { get; set; }
[Display(Name = "Local file")]
[NotMapped]
public HttpPostedFileBase File
{
get
{
return null;
}
set
{
try
{
MemoryStream target = new MemoryStream();
if (value.InputStream == null)
return;
value.InputStream.CopyTo(target);
InternalImage = target.ToArray();
}
catch (Exception ex)
{
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
}
}
[DisplayName("Item Picture URL")]
[StringLength(1024)]
public string ItemPictureUrl { get; set; }
public virtual Alphabet Alphabets { get; set; }
public virtual ICollection<Biographie> Biographies { get; set; }
public virtual ICollection<Individual> Individuals { get; set; }
public virtual ICollection<Familie> Families { get; set; }
public virtual ICollection<Relationship> FamilieSurname { get; set; }
public virtual ICollection<Relationship> FirstSurname { get; set; }
public virtual ICollection<Relationship> SecondSurname { get; set; }
// public virtual ICollection<Relationship> Relationships { get; set; }
}
}
The second one being "Familie", code as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Web;
namespace MvcNOK.Models
{
public class Familie
{
[Key]
public int FamilieId { get; set; }
//[Required]
[Display(Name = "Family Name")]
public int SurnameId { get; set; }
[Required]
[Display(Name = "Family Tree Name")]
public string Name { get; set; }
public virtual Surname Surnames { get; set; }
public virtual ICollection<Relationship> RelationshipFamilie { get; set; }
}
}
The third being "Individual", code is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Web;
namespace MvcNOK.Models
{
public class Individual
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
[Key]
public int IndividualId { get; set; }
[Required]
[Display(Name = "User")]
public string Email { get; set; }
[Required]
[Display(Name = "Letter of Surname")]
public int Alphabet { get; set; }
[Required]
[Display(Name = "Surname")]
public int Surname { get; set; }
[Required]
[Display(Name = "Full Name")]
public string Last { get; set; }
[Required]
[Display(Name = "Gender")]
public int GenderId { get; set; }
[Required]
[Display(Name = "Occupation")]
public string Occupation { get; set; }
[Required]
[Display(Name = "Date of birth.")]
public string DOB { get; set; }
[Required]
[Display(Name = "Era of birth.")]
public int EraId { get; set; }
[Required]
[Display(Name = "Main Country")]
public int NCountrie { get; set; }
[Required]
[Display(Name = "Country of birth")]
public int Countrie { get; set; }
[Required]
[Display(Name = "State of birth")]
public int State { get; set; }
[Required]
[Display(Name = "City of birth")]
public int Citie { get; set; }
[Required]
[Display(Name = "Source of birth")]
public string Source { get; set; }
[Display(Name = "Source Notes")]
public string Notes { get; set; }
public byte[] InternalImage { get; set; }
[Display(Name = "Local file")]
[NotMapped]
public HttpPostedFileBase File
{
get
{
return null;
}
set
{
try
{
MemoryStream target = new MemoryStream();
if (value.InputStream == null)
return;
value.InputStream.CopyTo(target);
InternalImage = target.ToArray();
}
catch (Exception ex)
{
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
}
}
[DisplayName("Item Picture URL")]
[StringLength(1024)]
public string ItemPictureUrl { get; set; }
[Display(Name = "Date of Death.")]
public string DOD { get; set; }
[Required]
[Display(Name = "Era of death.")]
public int DEraId { get; set; }
[Display(Name = "Main Country")]
public int NDcountrie { get; set; }
[Display(Name = "Country of Death")]
public int DCountrie { get; set; }
[Display(Name = "State of Death")]
public int DState { get; set; }
[Display(Name = "City of Death")]
public int DCitie { get; set; }
[Display(Name = "Source of Death")]
public string DSource { get; set; }
[Display(Name = "Source Notes")]
public string DNotes { get; set; }
public virtual Gender Genders { get; set; }
public virtual Alphabet Alphabets { get; set; }
public virtual Surname Surnames { get; set; }
public virtual NCountrie NCountries { get; set; }
public virtual Countrie Countries { get; set; }
public virtual State States { get; set; }
public virtual Citie Cities { get; set; }
public virtual NDcountrie NDcountries { get; set; }
public virtual DCountrie DCountries { get; set; }
public virtual DState DStates { get; set; }
public virtual DCitie DCities { get; set; }
public virtual DEra DEras { get; set; }
public virtual Era Eras { get; set; }
public virtual ICollection<Biographie> Biographies { get; set; }
public virtual ICollection<Relationship> FirstIndividual { get; set; }
public virtual ICollection<Relationship> SecondIndividual { get; set; }
}
}
The forth being "Kinship", the code is as follows:
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace MvcNOK.Models
{
public class Kinship
{
[Key]
public int KinshipId { get; set; }
[Required]
[Display(Name = "Kinship")]
public string Name { get; set; }
[Required]
[Display(Name = "Degree")]
public string Degree { get; set; }
[Required]
[Display(Name = "Genetics")]
public string Genetic { get; set; }
[Required]
[Display(Name = "Description")]
public string Description { get; set; }
public virtual ICollection<KRole> KRoles { get; set; }
public virtual ICollection<Relationship> FirstKinship { get; set; }
public virtual ICollection<Relationship> SecondKinship { get; set; }
//public virtual ICollection<Relationship> Relationships { get; set; }
}
}
The fifth being "KRole", the is as follows:
using MvcNOK.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace MvcNOK.Models
{
public class KRole
{
[Key]
public int KRoleId { get; set; }
public int KinshipId { get; set; }
[Required]
[Display(Name = "Relationship to First Role")]
public string Name { get; set; }
public virtual Kinship Kinships { get; set; }
public virtual ICollection<Relationship> FirstKRole { get; set; }
public virtual ICollection<Relationship> SecondKRole { get; set; }
//public virtual ICollection<Relationship> Relationships { get; set; }
}
}
The Identity Context, "IdentityModel", the code is as follows:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using MvcNOK.Models;
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
namespace IdentitySample.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
// Here we add a byte to Save the user Profile Pictuer
public byte[] UserPhoto { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<Alphabet> Alphabets { get; set; }
public DbSet<Surname> Surnames { get; set; }
public DbSet<NCountrie> NCountries { get; set; }
public DbSet<NDcountrie> NDcountries { get; set; }
public DbSet<Countrie> Countries { get; set; }
public DbSet<DCountrie> DCountries { get; set; }
public DbSet<State> States { get; set; }
public DbSet<DState> DStates { get; set; }
public DbSet<Citie> Cities { get; set; }
public DbSet<DCitie> DCities { get; set; }
public DbSet<Gender> Genders { get; set; }
public DbSet<Era> Eras { get; set; }
public DbSet<DEra> DEras { get; set; }
public DbSet<Individual> Individuals { get; set; }
public DbSet<TType> TTypes { get; set; }
public DbSet<TCategorie> TCategories { get; set; }
public DbSet<Title> Titles { get; set; }
public DbSet<Biographie> Biographies { get; set; }
public DbSet<Kinship> Kinships { get; set; }
public DbSet<KRole> KRoles { get; set; }
public DbSet<Familie> Families { get; set; }
public DbSet<Relationship> Relationships { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.States)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.State)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Alphabets)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.Alphabet)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Countries)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.Countrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Cities)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.Citie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Eras)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.EraId)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Genders)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.GenderId)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.DCountries)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.DCountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.DStates)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.DState)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.DCities)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.DCitie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.DEras)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.DEraId)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.Surnames)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.Surname)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.NCountries)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.NCountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Individual>()
.HasRequired(m => m.NDcountries)
.WithMany(t => t.Individuals)
.HasForeignKey(m => m.NDcountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<TType>()
.HasRequired(m => m.TCategories)
.WithMany(t => t.TTypes)
.HasForeignKey(m => m.TCategorie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.TCategories)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.TCategorie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.Alphabets)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.Alphabet)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.Surnames)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.Surname)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.NCountries)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.NCountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.Countries)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.Countrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.Individuals)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.Individual)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.Titles)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.Title)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Biographie>()
.HasRequired(m => m.TTypes)
.WithMany(t => t.Biographies)
.HasForeignKey(m => m.TType)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Familie>()
.HasRequired(m => m.Surnames)
.WithMany(t => t.Families)
.HasForeignKey(m => m.SurnameId)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FirstAlphabets)
.WithMany(t => t.FirstAlphabet)
.HasForeignKey(m => m.FAlphabet)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FirstSurnames)
.WithMany(t => t.FirstSurname)
.HasForeignKey(m => m.FSurname)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FirstIndividuals)
.WithMany(t => t.FirstIndividual)
.HasForeignKey(m => m.FIndividual)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FirstKinships)
.WithMany(t => t.FirstKinship)
.HasForeignKey(m => m.FKinship)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FirstRoles)
.WithMany(t => t.FirstKRole)
.HasForeignKey(m => m.FRole)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.SecondAlphabets)
.WithMany(t => t.SecondAlphabet)
.HasForeignKey(m => m.SAlphabet)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.SecondSurnames)
.WithMany(t => t.SecondSurname)
.HasForeignKey(m => m.SSurname)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.SecondIndividuals)
.WithMany(t => t.SecondIndividual)
.HasForeignKey(m => m.SIndividual)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.SecondKinships)
.WithMany(t => t.SecondKinship)
.HasForeignKey(m => m.SKinship)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.SecondRoles)
.WithMany(t => t.SecondKRole)
.HasForeignKey(m => m.SRole)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.Eras)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.EraId)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.NCountries)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.NCountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.Countries)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.Countrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.States)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.State)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.Cities)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.Citie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.NDcountries)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.NDcountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.DCountries)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.DCountrie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.DStates)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.DState)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.DCities)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.DCitie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.DCities)
.WithMany(t => t.Relationships)
.HasForeignKey(m => m.DCitie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.RelationshipFamilies)
.WithMany(t => t.RelationshipFamilie)
.HasForeignKey(m => m.RFamilie)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Relationship>()
.HasRequired(m => m.FamilieSurnames)
.WithMany(t => t.FamilieSurname)
.HasForeignKey(m => m.FaSurname)
.WillCascadeOnDelete(false);
}
static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
The controller "RelationshipController", the code is as follows:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using IdentitySample.Models;
using MvcNOK.Models;
namespace MvcNOK.Controllers
{
public class RelationshipsController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: Relationships
public ActionResult Index()
{
var relationships = db.Relationships.Include(r => r.Cities).Include(r => r.Countries).Include(r => r.DCities).Include(r => r.DCountries).Include(r => r.DEras).Include(r => r.DStates).Include(r => r.Eras).Include(r => r.FamilieSurnames).Include(r => r.FirstAlphabets).Include(r => r.FirstIndividuals).Include(r => r.FirstKinships).Include(r => r.FirstRoles).Include(r => r.FirstSurnames).Include(r => r.NCountries).Include(r => r.NDcountries).Include(r => r.RelationshipFamilies).Include(r => r.SecondAlphabets).Include(r => r.SecondIndividuals).Include(r => r.SecondKinships).Include(r => r.SecondRoles).Include(r => r.SecondSurnames).Include(r => r.States);
return View(relationships.ToList());
}
// GET: Relationships/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Relationship relationship = db.Relationships.Find(id);
if (relationship == null)
{
return HttpNotFound();
}
return View(relationship);
}
// GET: Relationships/Create
[Authorize]
public ActionResult Create()
{
ViewBag.Citie = new SelectList(db.Cities, "CitieId", "Name");
ViewBag.Countrie = new SelectList(db.Countries, "CountrieId", "Name");
ViewBag.DCitie = new SelectList(db.DCities, "DCitieId", "Name");
ViewBag.DCountrie = new SelectList(db.DCountries, "DCountrieId", "Name");
ViewBag.DEraId = new SelectList(db.DEras, "DEraId", "Name");
ViewBag.DState = new SelectList(db.DStates, "DStateId", "Name");
ViewBag.EraId = new SelectList(db.Eras, "EraId", "Name");
ViewBag.FaSurname = new SelectList(db.Surnames, "SurnameId", "Name");
ViewBag.FAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter");
ViewBag.FIndividual = new SelectList(db.Individuals, "IndividualId", "Last");
ViewBag.FKinship = new SelectList(db.Kinships, "KinshipId", "Name");
ViewBag.FRole = new SelectList(db.KRoles, "KRoleId", "Name");
ViewBag.FSurname = new SelectList(db.Surnames, "SurnameId", "Name");
ViewBag.NCountrie = new SelectList(db.NCountries, "NCountrieId", "Name");
ViewBag.NDcountrie = new SelectList(db.NDcountries, "NDcountrieId", "Name");
ViewBag.RFamilie = new SelectList(db.Families, "FamilieId", "Name");
ViewBag.SAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter");
ViewBag.SIndividual = new SelectList(db.Individuals, "IndividualId", "Last");
ViewBag.SKinship = new SelectList(db.Kinships, "KinshipId", "Name");
ViewBag.SRole = new SelectList(db.KRoles, "KRoleId", "Name");
ViewBag.SSurname = new SelectList(db.Surnames, "SurnameId", "Name");
ViewBag.State = new SelectList(db.States, "StateId", "Name");
return View();
}
public JsonResult RelationshipFamilieList(int Id)
{
var familie = from s in db.Families
where s.SurnameId == Id
select s;
return Json(new SelectList(familie.ToArray(), "FamilieId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<Familie> GetRelationshipFamilie(int SurnameId)
{
return db.Families.Where(m => m.SurnameId == SurnameId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByFamilieSurnameId(string Name)
{
var FamilieList = this.GetRelationshipFamilie(Convert.ToInt32(Name));
var FamilieData = FamilieList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.SurnameId.ToString(),
});
return Json(FamilieData, JsonRequestBehavior.AllowGet);
}
public JsonResult FirstSurnameList(int Id)
{
var surname = from s in db.Surnames
where s.AlphabetId == Id
select s;
return Json(new SelectList(surname.ToArray(), "SurnameId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<Surname> GetFirstSurname(int AlphabetId)
{
return db.Surnames.Where(m => m.AlphabetId == AlphabetId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByFirstAphabetId(string Name)
{
var SurnameList = this.GetFirstSurname(Convert.ToInt32(Name));
var SurnameData = SurnameList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.AlphabetId.ToString(),
});
return Json(SurnameData, JsonRequestBehavior.AllowGet);
}
public JsonResult FirstIndividualList(int Id)
{
var individual = from s in db.Individuals
where s.Surname == Id
select s;
return Json(new SelectList(individual.ToArray(), "IndividualId", "Last"), JsonRequestBehavior.AllowGet);
}
public IList<Individual> GetFirstIndividual(int SurnameId)
{
return db.Individuals.Where(m => m.Surname == SurnameId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByFirstSurnameId(string Last)
{
var IndividualList = this.GetFirstIndividual(Convert.ToInt32(Last));
var IndividualData = IndividualList.Select(m => new SelectListItem()
{
Text = m.Last,
Value = m.Surname.ToString(),
});
return Json(IndividualData, JsonRequestBehavior.AllowGet);
}
public JsonResult RoleList(int Id)
{
var role = from s in db.KRoles
where s.KinshipId == Id
select s;
return Json(new SelectList(role.ToArray(), "KRoleId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<KRole> GetRole(int KinshipId)
{
return db.KRoles.Where(m => m.KinshipId == KinshipId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByKinshipId(string Name)
{
var KRoleList = this.GetRole(Convert.ToInt32(Name));
var KRoleData = KRoleList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.KinshipId.ToString(),
});
return Json(KRoleData, JsonRequestBehavior.AllowGet);
}
public JsonResult SecondSurnameList(int Id)
{
var surname = from s in db.Surnames
where s.AlphabetId == Id
select s;
return Json(new SelectList(surname.ToArray(), "SurnameId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<Surname> GetSecondSurname(int AlphabetId)
{
return db.Surnames.Where(m => m.AlphabetId == AlphabetId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesBySecondAphabetId(string Name)
{
var SurnameList = this.GetSecondSurname(Convert.ToInt32(Name));
var SurnameData = SurnameList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.AlphabetId.ToString(),
});
return Json(SurnameData, JsonRequestBehavior.AllowGet);
}
public JsonResult SecondIndividualList(int Id)
{
var individual = from s in db.Individuals
where s.Surname == Id
select s;
return Json(new SelectList(individual.ToArray(), "IndividualId", "Last"), JsonRequestBehavior.AllowGet);
}
public IList<Individual> GetSecondIndividual(int SurnameId)
{
return db.Individuals.Where(m => m.Surname == SurnameId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesBySecondSurnameId(string Last)
{
var IndividualList = this.GetFirstIndividual(Convert.ToInt32(Last));
var IndividualData = IndividualList.Select(m => new SelectListItem()
{
Text = m.Last,
Value = m.Surname.ToString(),
});
return Json(IndividualData, JsonRequestBehavior.AllowGet);
}
public JsonResult SecondRoleList(int Id)
{
var role = from s in db.KRoles
where s.KinshipId == Id
select s;
return Json(new SelectList(role.ToArray(), "KRoleId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<KRole> GetSecondRole(int KinshipId)
{
return db.KRoles.Where(m => m.KinshipId == KinshipId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesBySecondKinshipId(string Name)
{
var KRoleList = this.GetSecondRole(Convert.ToInt32(Name));
var KRoleData = KRoleList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.KinshipId.ToString(),
});
return Json(KRoleData, JsonRequestBehavior.AllowGet);
}
public JsonResult CountrieList(int Id)
{
var countrie = from s in db.Countries
where s.NCountrieId == Id
select s;
return Json(new SelectList(countrie.ToArray(), "CountrieId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<Countrie> GetCountrie(int NCountrieId)
{
return db.Countries.Where(m => m.NCountrieId == NCountrieId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByNCountrieId(string Name)
{
var NCountrieList = this.GetCountrie(Convert.ToInt32(Name));
var NCountrieData = NCountrieList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.NCountrieId.ToString(),
});
return Json(NCountrieData, JsonRequestBehavior.AllowGet);
}
public JsonResult StateList(int Id)
{
var state = from s in db.States
where s.CountrieId == Id
select s;
return Json(new SelectList(state.ToArray(), "StateId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<State> GetState(int CountrieId)
{
return db.States.Where(m => m.CountrieId == CountrieId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByStateId(string Name)
{
var StateList = this.GetState(Convert.ToInt32(Name));
var StateData = StateList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.CountrieId.ToString(),
});
return Json(StateData, JsonRequestBehavior.AllowGet);
}
public JsonResult CitieList(int Id)
{
var citie = from s in db.Cities
where s.StateId == Id
select s;
return Json(new SelectList(citie.ToArray(), "CitieId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<Citie> GetCitie(int StateId)
{
return db.Cities.Where(m => m.StateId == StateId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByCitieId(string Name)
{
var CitieList = this.GetCitie(Convert.ToInt32(Name));
var CitieData = CitieList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.StateId.ToString(),
});
return Json(CitieData, JsonRequestBehavior.AllowGet);
}
public JsonResult DCountrieList(int Id)
{
var dCountrie = from s in db.DCountries
where s.NDcountrieId == Id
select s;
return Json(new SelectList(dCountrie.ToArray(), "DCountrieId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<DCountrie> GetDCountrie(int NDcountrieId)
{
return db.DCountries.Where(m => m.NDcountrieId == NDcountrieId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByDCountrieId(string Name)
{
var DCountrieList = this.GetDCountrie(Convert.ToInt32(Name));
var DCountrieData = DCountrieList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.NDcountrieId.ToString(),
});
return Json(DCountrieData, JsonRequestBehavior.AllowGet);
}
public JsonResult DStateList(int Id)
{
var dState = from s in db.DStates
where s.DCountrieId == Id
select s;
return Json(new SelectList(dState.ToArray(), "DStateId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<DState> GetDState(int DCountrieId)
{
return db.DStates.Where(m => m.DCountrieId == DCountrieId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByDStateId(string Name)
{
var DStateList = this.GetDState(Convert.ToInt32(Name));
var DStateData = DStateList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.DCountrieId.ToString(),
});
return Json(DStateData, JsonRequestBehavior.AllowGet);
}
public JsonResult DCitieList(int Id)
{
var dCitie = from s in db.DCities
where s.DStateId == Id
select s;
return Json(new SelectList(dCitie.ToArray(), "DCitieId", "Name"), JsonRequestBehavior.AllowGet);
}
public IList<DCitie> GetDCitie(int DStateId)
{
return db.DCities.Where(m => m.DStateId == DStateId).ToList();
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult LoadClassesByDCitieId(string Name)
{
var DCitieList = this.GetDCitie(Convert.ToInt32(Name));
var DCitieData = DCitieList.Select(m => new SelectListItem()
{
Text = m.Name,
Value = m.DStateId.ToString(),
});
return Json(DCitieData, JsonRequestBehavior.AllowGet);
}
// POST: Relationships/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost, ValidateInput(false)]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult Create(Relationship relationship)
{
if (ModelState.IsValid)
{
db.Relationships.Add(relationship);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.Citie = new SelectList(db.Cities, "CitieId", "Name", relationship.Citie);
ViewBag.Countrie = new SelectList(db.Countries, "CountrieId", "Name", relationship.Countrie);
ViewBag.DCitie = new SelectList(db.DCities, "DCitieId", "Name", relationship.DCitie);
ViewBag.DCountrie = new SelectList(db.DCountries, "DCountrieId", "Name", relationship.DCountrie);
ViewBag.DEraId = new SelectList(db.DEras, "DEraId", "Name", relationship.DEraId);
ViewBag.DState = new SelectList(db.DStates, "DStateId", "Name", relationship.DState);
ViewBag.EraId = new SelectList(db.Eras, "EraId", "Name", relationship.EraId);
ViewBag.FaSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FaSurname);
ViewBag.FAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.FAlphabet);
ViewBag.FIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.FIndividual);
ViewBag.FKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.FKinship);
ViewBag.FRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.FRole);
ViewBag.FSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FSurname);
ViewBag.NCountrie = new SelectList(db.NCountries, "NCountrieId", "Name", relationship.NCountrie);
ViewBag.NDcountrie = new SelectList(db.NDcountries, "NDcountrieId", "Name", relationship.NDcountrie);
ViewBag.RFamilie = new SelectList(db.Families, "FamilieId", "Name", relationship.RFamilie);
ViewBag.SAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.SAlphabet);
ViewBag.SIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.SIndividual);
ViewBag.SKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.SKinship);
ViewBag.SRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.SRole);
ViewBag.SSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.SSurname);
ViewBag.State = new SelectList(db.States, "StateId", "Name", relationship.State);
return View(relationship);
}
// GET: Relationships/Edit/5
[Authorize]
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Relationship relationship = db.Relationships.Find(id);
if (relationship == null)
{
return HttpNotFound();
}
ViewBag.Citie = new SelectList(db.Cities, "CitieId", "Name", relationship.Citie);
ViewBag.Countrie = new SelectList(db.Countries, "CountrieId", "Name", relationship.Countrie);
ViewBag.DCitie = new SelectList(db.DCities, "DCitieId", "Name", relationship.DCitie);
ViewBag.DCountrie = new SelectList(db.DCountries, "DCountrieId", "Name", relationship.DCountrie);
ViewBag.DEraId = new SelectList(db.DEras, "DEraId", "Name", relationship.DEraId);
ViewBag.DState = new SelectList(db.DStates, "DStateId", "Name", relationship.DState);
ViewBag.EraId = new SelectList(db.Eras, "EraId", "Name", relationship.EraId);
ViewBag.FaSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FaSurname);
ViewBag.FAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.FAlphabet);
ViewBag.FIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.FIndividual);
ViewBag.FKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.FKinship);
ViewBag.FRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.FRole);
ViewBag.FSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FSurname);
ViewBag.NCountrie = new SelectList(db.NCountries, "NCountrieId", "Name", relationship.NCountrie);
ViewBag.NDcountrie = new SelectList(db.NDcountries, "NDcountrieId", "Name", relationship.NDcountrie);
ViewBag.RFamilie = new SelectList(db.Families, "FamilieId", "Name", relationship.RFamilie);
ViewBag.SAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.SAlphabet);
ViewBag.SIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.SIndividual);
ViewBag.SKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.SKinship);
ViewBag.SRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.SRole);
ViewBag.SSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.SSurname);
ViewBag.State = new SelectList(db.States, "StateId", "Name", relationship.State);
return View(relationship);
}
// POST: Relationships/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost, ValidateInput(false)]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult Edit(Relationship relationship)
{
if (ModelState.IsValid)
{
db.Entry(relationship).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.Citie = new SelectList(db.Cities, "CitieId", "Name", relationship.Citie);
ViewBag.Countrie = new SelectList(db.Countries, "CountrieId", "Name", relationship.Countrie);
ViewBag.DCitie = new SelectList(db.DCities, "DCitieId", "Name", relationship.DCitie);
ViewBag.DCountrie = new SelectList(db.DCountries, "DCountrieId", "Name", relationship.DCountrie);
ViewBag.DEraId = new SelectList(db.DEras, "DEraId", "Name", relationship.DEraId);
ViewBag.DState = new SelectList(db.DStates, "DStateId", "Name", relationship.DState);
ViewBag.EraId = new SelectList(db.Eras, "EraId", "Name", relationship.EraId);
ViewBag.FaSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FaSurname);
ViewBag.FAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.FAlphabet);
ViewBag.FIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.FIndividual);
ViewBag.FKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.FKinship);
ViewBag.FRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.FRole);
ViewBag.FSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.FSurname);
ViewBag.NCountrie = new SelectList(db.NCountries, "NCountrieId", "Name", relationship.NCountrie);
ViewBag.NDcountrie = new SelectList(db.NDcountries, "NDcountrieId", "Name", relationship.NDcountrie);
ViewBag.RFamilie = new SelectList(db.Families, "FamilieId", "Name", relationship.RFamilie);
ViewBag.SAlphabet = new SelectList(db.Alphabets, "AlphabetId", "Letter", relationship.SAlphabet);
ViewBag.SIndividual = new SelectList(db.Individuals, "IndividualId", "Last", relationship.SIndividual);
ViewBag.SKinship = new SelectList(db.Kinships, "KinshipId", "Name", relationship.SKinship);
ViewBag.SRole = new SelectList(db.KRoles, "KRoleId", "Name", relationship.SRole);
ViewBag.SSurname = new SelectList(db.Surnames, "SurnameId", "Name", relationship.SSurname);
ViewBag.State = new SelectList(db.States, "StateId", "Name", relationship.State);
return View(relationship);
}
// GET: Relationships/Delete/5
[Authorize(Roles = "Admin")]
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Relationship relationship = db.Relationships.Find(id);
if (relationship == null)
{
return HttpNotFound();
}
return View(relationship);
}
// POST: Relationships/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Relationship relationship = db.Relationships.Find(id);
db.Relationships.Remove(relationship);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
The view "Create.cshtml", the code is as follows:
@model MvcNOK.Models.Relationship
@{
ViewBag.Title = "Create";
}
@Scripts.Render("~/bundles/jquery")
<script type="text/jscript">
$(function () {
$('#FamilieSurname').change(function () {
$.getJSON('/Relationships/RelationshipFamilieList/' + $('#FamilieSurname').val(), function (data) {
var items = '<option>Select a Family Tree Name</option>';
$.each(data, function (i, familie) {
items += "<option value='" + familie.Value + "'>" + familie.Text + "</option>";
});
$('#RelationshipFamilie').html(items);
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#FirstAlphabet').change(function () {
$.getJSON('/Relationships/FirstSurnameList/' + $('#FirstAlphabet').val(), function (data) {
var items = '<option>Select a Surname</option>';
$.each(data, function (i, surname) {
items += "<option value='" + surname.Value + "'>" + surname.Text + "</option>";
});
$('#FirstSurname').html(items);
});
});
$(function () {
$('#FirstSurname').change(function () {
$.getJSON('/Relationships/FirstIndividualList/' + $('#FirstSurname').val(), function (data) {
var items = '<option>Select a Person</option>';
$.each(data, function (i, individual) {
items += "<option value='" + individual.Value + "'>" + individual.Text + "</option>";
});
$('#FirstIndividual').html(items);
});
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#FirstKinship').change(function () {
$.getJSON('/Relationships/RoleList/' + $('#FirstKinship').val(), function (data) {
var items = '<option>Select a Role in the First Individual Relationship</option>';
$.each(data, function (i, krole) {
items += "<option value='" + krole.Value + "'>" + krole.Text + "</option>";
});
$('#FirstKRole').html(items);
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#SecondAlphabet').change(function () {
$.getJSON('/Relationships/SecondSurnameList/' + $('#SecondAlphabet').val(), function (data) {
var items = '<option>Select a Surname</option>';
$.each(data, function (i, surname) {
items += "<option value='" + surname.Value + "'>" + surname.Text + "</option>";
});
$('#SecondSurname').html(items);
});
});
$(function () {
$('#SecondSurname').change(function () {
$.getJSON('/Relationships/SecondIndividualList/' + $('#SecondSurname').val(), function (data) {
var items = '<option>Select a Person</option>';
$.each(data, function (i, individual) {
items += "<option value='" + individual.Value + "'>" + individual.Text + "</option>";
});
$('#SecondIndividual').html(items);
});
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#SecondKinship').change(function () {
$.getJSON('/Relationships/SecondRoleList/' + $('#SecondKinship').val(), function (data) {
var items = '<option>Select a Role in the Second Individual Relationship</option>';
$.each(data, function (i, krole) {
items += "<option value='" + krole.Value + "'>" + krole.Text + "</option>";
});
$('#SecondKRole').html(items);
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#NCountrie').change(function () {
$.getJSON('/Relationships/CountrieList/' + $('#NCountrie').val(), function (data) {
var items = '<option>Select a Country</option>';
$.each(data, function (i, countrie) {
items += "<option value='" + countrie.Value + "'>" + countrie.Text + "</option>";
});
$('#Countrie').html(items);
});
});
$(function () {
$('#Countrie').change(function () {
$.getJSON('/Relationships/StateList/' + $('#Countrie').val(), function (data) {
var items = '<option>Select a State or Province</option>';
$.each(data, function (i, state) {
items += "<option value='" + state.Value + "'>" + state.Text + "</option>";
});
$('#State').html(items);
});
});
$(function () {
$('#State').change(function () {
$.getJSON('/Relationships/CitieList/' + $('#State').val(), function (data) {
var items = '<option>Select a City</option>';
$.each(data, function (i, citie) {
items += "<option value='" + citie.Value + "'>" + citie.Text + "</option>";
});
$('#Citie').html(items);
});
});
});
});
});
</script>
<script type="text/jscript">
$(function () {
$('#NDcountrie').change(function () {
$.getJSON('/Relationships/DCountrieList/' + $('#NDcountrie').val(), function (data) {
var items = '<option>Select a Country</option>';
$.each(data, function (i, dcountrie) {
items += "<option value='" + dcountrie.Value + "'>" + dcountrie.Text + "</option>";
});
$('#DCountrie').html(items);
});
});
$(function () {
$('#DCountrie').change(function () {
$.getJSON('/Relationships/DStateList/' + $('#DCountrie').val(), function (data) {
var items = '<option>Select a State or Province</option>';
$.each(data, function (i, dstate) {
items += "<option value='" + dstate.Value + "'>" + dstate.Text + "</option>";
});
$('#DState').html(items);
});
});
$(function () {
$('#DState').change(function () {
$.getJSON('/Relationships/DCitieList/' + $('#DState').val(), function (data) {
var items = '<option>Select a City</option>';
$.each(data, function (i, dcitie) {
items += "<option value='" + dcitie.Value + "'>" + dcitie.Text + "</option>";
});
$('#DCitie').html(items);
});
});
});
});
});
</script>
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<script src="~/Scripts/ckeditor/adapters/jquery.js"></script>
<script>
CKEDITOR.replace('ckeditor', {
// Pressing Enter will create a new <div> element.
enterMode: CKEDITOR.ENTER_DIV,
// Pressing Shift+Enter will create a new <p> element.
shiftEnterMode: CKEDITOR.ENTER_P
} );
</script>
@using (Html.BeginForm("Create", "Relationships", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Relationship</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FaSurname, "Surname of the Family Tree", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("FamilieSurname", ViewBag.FaSurname as SelectList, "Select a Surname", new { id = "FamilieSurname" })
@Html.ValidationMessageFor(model => model.FaSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RFamilie, "RFamilie", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="RelationshipFamilie" name="RelationshipFamilie"></select>
@Html.ValidationMessageFor(model => model.RFamilie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FAlphabet, "First Relationship Letter", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("FirstAlphabet", ViewBag.FAlphabet as SelectList, "Select a Letter", new { id = "FirstAlphabet" })
@Html.ValidationMessageFor(model => model.FAlphabet, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FSurname, "First Relationship Surname", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="FirstSurname" name="FirstSurname"></select>
@Html.ValidationMessageFor(model => model.FSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FIndividual, "First person Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="FirstIndividual" name="FirstIndividual"></select>
@Html.ValidationMessageFor(model => model.FIndividual, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FKinship, "First Kinship Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("FirstKinship", ViewBag.FKinship as SelectList, "Select a Kinship", new { id = "FirstKinship" })
@Html.ValidationMessageFor(model => model.FKinship, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FRole, "First Kinship Role of Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="FirstKRole" name="FirstKRole"></select>
@Html.ValidationMessageFor(model => model.FRole, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SAlphabet, "Second Relationship Letter", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("SecondAlphabet", ViewBag.SAlphabet as SelectList, "Select a Letter", new { id = "SecondAlphabet" })
@Html.ValidationMessageFor(model => model.SAlphabet, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SSurname, "Second Relationship Surname", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="SecondSurname" name="SecondSurname"></select>
@Html.ValidationMessageFor(model => model.SSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SIndividual, "Second Person Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="SecondIndividual" name="SecondIndividual"></select>
@Html.ValidationMessageFor(model => model.SIndividual, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SKinship, "Second Kinship Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("SecondKinship", ViewBag.SKinship as SelectList, "Select a Kinship", new { id = "SecondKinship" })
@Html.ValidationMessageFor(model => model.SKinship, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SRole, "Second Role in Kinship Relationship", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="SecondKRole" name="SecondKRole"></select>
@Html.ValidationMessageFor(model => model.SRole, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Start, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Start, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Start, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EraId, "Era", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("EraId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.EraId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NCountrie, "Main Country of Today", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("NCountrie", ViewBag.NCountrieId as SelectList, "Select a Country Area", new { id = "NCountrie" })
@Html.ValidationMessageFor(model => model.NCountrie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Countrie, "Country of Time Period", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="Countrie" name="Countrie"></select>
@Html.ValidationMessageFor(model => model.Countrie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.State, "State", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="State" name="State"></select>
@Html.ValidationMessageFor(model => model.State, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Citie, "City", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="Citie" name="Citie"></select>
@Html.ValidationMessageFor(model => model.Citie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Source, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.Source, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Source, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Notes, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.Notes, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.Notes, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.End, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.End, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.End, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DEraId, "Era", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("DEraId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.DEraId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NDcountrie, "Main Country of Today", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("NDcountrie", ViewBag.NDcountrieId as SelectList, "Select a Country Area", new { id = "NDcountrie" })
@Html.ValidationMessageFor(model => model.NDcountrie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DCountrie, "Country of Time Period", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="DCountrie" name="DCountrie"></select>
@Html.ValidationMessageFor(model => model.DCountrie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DState, "State", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="DState" name="DState"></select>
@Html.ValidationMessageFor(model => model.DState, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DCitie, "City", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="DCitie" name="DCitie"></select>
@Html.ValidationMessageFor(model => model.DCitie, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ESource, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.ESource, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.ESource, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ENotes, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.ENotes, new { @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.ENotes, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
The way this page should work is that the Relationship model will choose from the Individual Model a FirstIndividual and SecondIndividual, and from the Surname Model a FamilieSurname, FirstSurname, and SecondSurname, from the Kinship Model a FirstKinship and SecondKinship, from the KRole Model FirstRole and SecondRole, from the Alpahbet Model FirstAlphabet and SecondAlphabet. I had unique foreign keys, so I would think that there would be no conflict. I am using a cascade dropdown list for these tables, which is being pick up in the create.cshtml page. I get the conflict error when I try to insert the data.
If you can help solve this it would be very much appreciated.
I look forward to hering from you soon.
Thanks
A