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

Gradually Increasing Movement Speed Using Normalized Speed
asp.net checkbox checked event take longer time to respond and checkbox checked when it is processing it give anoynomous result
What clr.ImportExtensions exactly does?
Write data from View to each row in database
Paerser Error when loading C# ASP.NET website hosted on GoDaddy [duplicate]
c# EF Model has foreign key to another model
Unit Test Async WebAPI 2 Get Request
Error while generating views with with Mysql and EF6
Identifying specific field that fails a conversion during a Database Query
EF Core “Invalid column name 'Discriminator'” error with inheritance
Gridview post back event
Got Unhandled Exception :: System.Xml.XmlException: Text node cannot appear in this state
“Syntax error in FROM clause” using OleDb in C# but no error for same query in Access itself
Custom Effect on model instance makes BasicEffect unrecognizeable on other (separately loaded) instance
Issue with Xamarin App Connecting to WCF Service over https
Reactive Extensions / UI cache web request data

Categories

HOME
logging
swift3
android-ndk
gaussian
crm
itext7
esxi
download
powerquery
pdf-generation
revit-api
google-my-business-api
runtime
theory
mongoimport
wowza
mbed
browsermob
react-select
responsive
infopath
appsettings
greensock
airbnb
hl7-fhir
ampscript
single-page-application
include-path
advertising
sasl
knapsack-problem
jopendocument
mongoose-im
utc
kundera
ocl
login-required
kubectl
snapkit
border-layout
hippocms
multi-user
console.readline
kepserverex
form-fields
stdin
jslider
delphi-xe
text-extraction
anonymous-function
google-chrome-storage
riemann
px4
fckeditor
dynatable
bipartite
disassembly
therubyracer
addressbook
portaudio
x12
hoare-logic
audiorecord
jde
camellia
pebble-js
skscene
jts
callfire
photogrammetry
mathics
numerical-recipes
caption
register-allocation
formbuilder
vundle
worklight-appcenter
indic
mvcgrid
lettuce
pidgin
autofilter
netbeans-plugins
adabas
thucydides
usersettings
symbian3
bho
servicemanager
cloudmade
microsoft-speech-platform
screensharing
nserror
optimistic-concurrency
datasheet
mysql-connector
jqzoom
virtual-printer
vectorwise
recess
sessiontracking
google-local-search
jquery-attributes
user-preferences
wtsapi32
high-load

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