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

Visual Studio 2015 Community - XAML Desginer extremely slow to load
Merging touching polygons giving wrong result
Getting users from active directory using openldap c#
How to allow only one checked box in the gridview?
Null Reference Exception being thrown when using a data template selector in a user control WPF
Synchronous Task Execution in C#
Having to click button twice to trigger postback in asp.net
How to execute a method after completion of three proccesses in .net
Parallelize transitive reduction
Why does Visual Studio create double closing brackets for C#6 interpolated strings?
Why does XNA upgrade VS 2010 from v. 10 to v. 11?
Download All Blobs from single Azure Container
Telerik HTML5 Report Viewer - Error loading the report viewer's templates
Extracting image from a slide of a .pptx
How to sort in EF parents by number of children of children of children?
Fetch Data from database to Fullcalendar.io using Json

Categories

HOME
pact
swift3
mobile
domain-driven-design
dronekit
phantomjs
reference
magento-1.9.2.1
nltk
pandoc
liquidsoap
scapy
rename
adroitlogic
http-status-codes
fine-uploader
background-image
smooth-scrolling
vivado-hls
single-page-application
turn.js
bug-reporting
pushbullet
ecmascript-2017
ps
android-wear-2.0
datastax-enterprise
workflow-foundation
angular-schema-form
undo
akamai
loopback
unity3d-5
pymunk
ragel
byobu
usernotifications
ape-phylo
jquery-ui-slider
taiga
nshttpurlresponse
cakephp-3.2
risc
gridgain
infovis
remap
g77
enet
typewriter
reloaddata
lightspeed
ownership
optional-parameters
class-design
hoare-logic
mrunit
avaudiorecorder
aws-kms
razorengine
usps
wordpress-plugin
transbase
vspackage
targetprocess
mergecursor
screen-lock
nexusdb
optimistic-locking
cordova-3
formbuilder
vundle
dirname
dotcmis
scjp
traceur
nodeunit
android-jack-and-jill
carrier
nop
adabas
facebook-likebox
xcode6.1-gm-seed
nsnumber
violation
gpl
yii-components
inflate
jquery-1.8
dancer
nsscrollview
django-1.4
inserthtml
datejs
pex-and-moles
functional-specifications
onunload
nyromodal
p4.net
large-data-volumes
carbon-emacs
helios

Resources

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
javascript
java
csharp
php
python
android
jquery
ruby
ios
html