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

Updating ContentBlock pulled from pageManager.LoadControl(). Sitefinity 5
How I can see a Image in my ImageButton?
Cannot apply Click event to the button with the custom button style
Need to bind DataList with Two DataSources
Difference between IList<T> and List<T> [duplicate]
How to use Pascal Casing and Camel Casing for Short Acronyms in C#?
How to intercept packets sent by a application and check what they have? [closed]
A method to sort through html files [closed]
SmtpClient.SendAsync() not receiving all messages I sent
OpenFileDialog no show in different AppDomain
Storing Reference to Non-Static Method
What is the best practice for login attempts and locking account accounts in asp.net membership provider
What's the deal with the version number attached the name of the dll?
How would you invoke an event with reflection?
Conditional Compile of Generic Methods
VS WinForm designer always changes custom constructor?

Categories

HOME
oop
pelican
microcontroller
lithium
liquidsoap
jquery-select2
scapy
box-api
resharper
jetbrains
yui
multibinding
civicrm
legend-properties
autologin
gpo
tcpdf
pydub
cloudformation
jbossfuse
ios9
jql
ng2-bootstrap
snapkit
jsonapi-resources
imageprocessor
dropdownbox
gitosis
respect-validation
motherboard
realloc
rtsp
queryover
armadillo
google-cloud-powershell
contenteditable
definition
nshttpurlresponse
grails-2.0
gridgain
reqif
emacs24
beanshell
riemann
codesniffer
trusted-computing
cosign-api
patching
web-optimization
google-app-engine-php
nonblocking
yfiles
libgcrypt
serial-communication
page-flipping
dpkt
jeet-grid
httpmodule
skview
strcpy
esri-arc-engine
alpha-beta-pruning
tigase
triplestore
twitter-finagle
winrun4j
pthreads-win32
starling-framework
android-jack-and-jill
carrier
svg-android
tlbimp
caroufredsel
objectdatasource
playing-cards
coinbase-php
system.transactions
rbm
setcookie
linqdatasource
qt5.1
cron4j
nsregularexpression
django-admin-tools
pinchzoom
rjs
openwrap
vectorwise
recess
jquery-click-event
nbehave
onunload
conditional-operator
qprocess
pixel-bender
authkit
jettison
memory-consumption

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
Mobile App
Mobile App
Mobile App