c#
Entity Framework One To One Relationship WithRequiredPrinciple saving entities without dependent entity
I am implementing one to one relationship in entity framework using code first approach. Below are my models. public class Course { public int CourseId { get; set; } public string CourseName { get; set; } public virtual Caption Caption { get; set; } } and this one public class Caption { public int CaptionId { get; set; } public string CaptionDesc { get; set; } public virtual Course Course { get; set; } } and in context I have used following code modelBuilder.Entity<Course>().HasRequired(c => c.Caption).WithRequiredPrincipal(c => c.Course); while reading this article here, One to One Relationship Example, They said that when let's say you are saving course entity without caption so exception will be thrown and entity framework won't let you store the entity. But When I did, I didn't got any exception. I can store both entities without any dependency. Please tell me what I am doing wrong. I am using entity framework 6 Edit: The tables looks as following.
1:1 relationships in entity framework are only supported when the tables share a primary key. Check out this article for help understanding: http://blog.bennymichielsen.be/2011/06/02/entity-framework-4-1-one-to-one-mapping/
Related Links
Array of Lists throws NullReferenceException
Nhibernate session management strategy for web application with background-workers?
Matching failed messages to their exceptions in NServiceBus using MSMQ
dependency properties in Silverlight
Shallow vs. Deep Copies in Immutable Objects
Recognize if the client is requesting page or something else in ASP.NET MVC custom HttpModule?
NHibernate: Prevent Refresh to trigger uninitialized Collections
Microsoft.Office.Interop.Word “Cannot activate application”
“The post's links must direct to the application's connect or canvas url”?
Dotnet :- How to make Autocomplete textbox search case insensitive?
C# thread functions not properly sharing a static data member
Problem passing object between WCF and ASMX using DataContracts
jqGrid row update
How do I add a number to a label in C#?
How to use a c# method in a sql stored procedure
Make text to have background + border