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

SQLite3 prepared statements for metro app
save page in c# webbrowser without savefiledialogue
How to avoid child class properties serialized as json in servicestack
ASP.NET Default.aspx
XAML-Binding to Control in ViewModel
MEF error in form designer?
create registry key, not the usual [closed]
SelectedValue which is invalid because it does not exist in the list of items
Operation not valid due to current state of the object error in IronRuby
is there any way I can generate a unique number that is NOT as long as a UUID (GUID)? [duplicate]
Using GUID as a Session Key?
IEnumerable<KeyValuePair<string, UserInformation>> vs IDictionary<string,UserInformation>
How to add two records with LINQ?
Sub-reports won't render to file SSRS
Where are paths previously used in the program stored (e.g. FileDialog paths)?
unity rotation issue on parent rotation

Categories

HOME
reactjs
max
azure-documentdb
sql-server-2014
openacc
angularjs-directive
richtextbox
restheart
ejb-3.0
google-search-appliance
guidewire
ng2-charts
repeater
facebook-marketing-api
taxonomy
beacon
gpo
gomobile
gsuite
git-submodules
arp
bootcamp
cocoa-scripting
flex3
linkurious
fisheye
vertical-alignment
jvisualvm
pexpect
rivets.js
stream-socket-client
visio-2010
xamarin-test-cloud
aot
liferay-ide
totalview
node.js-client
disassembly
catalyst
qudpsocket
racket-student-languages
toggleclass
dbi
joystick
xcode7.1
change-password
qtruby
queuing
salesforce-service-cloud
std
wonderware
yfiles
computability
magnet-uri
lytro
tooltwist
playn
log-analysis
minko
jad
javadb
nsnotificationcenter
windows-search
farpoint-spread
pidgin
android-jack-and-jill
logo-lang
mysql-error-1146
cab
kohana-orm
maven-webstart-plugin
pyxplot
removeall
cloudmade
qt5.1
certificate-revocation
event-propagation
animationdrawable
maven-eclipse-plugin
rollover
zend-acl
opengl-to-opengles
unauthorized
office-2003
hotfix
urlscan





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm