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

Save file on windows phone 8.1
Datagrid Combobox Seletected item Value to Textbox binding
Invoking generic method from Main using reflection
OOP Method Usage [closed]
Calculate Age based on Visit Date
How to update a TextView text (decode text effect)?
C# faculty : weird results [duplicate]
Which MVC version to start with [closed]
What is “88-type” in C# and how can i use it?
C# Regex to convert yyyyMMddhhmm
EntityFramework package version=“6.1.3” and Web config version 6.0.0.0?
How to read a binary formatted string from a file?
Why My combobox binding not working
convert timespan to datetime
call to method inside code behind file(aspx.cs file) from controller method
Casting exposes private data via getter method

Categories

HOME
youtube-api
gsm
pelican
python-requests
watson-iot
assign
ms-application-insights
travis-ci-cli
google-api-oauth
wkhtmltopdf
spring-data-solr
theory
decoding
hdf5
watson-dialog
sha1
luis
google-calendar-api3
civicrm
react-jsx
custom-component
vala
uipath
ppp
continuous-fourier
uibarbuttonitem
emr
jboss-arquillian
login-required
jql
language-detection
leaderboard
hippocms
outlook-2010
oracle-bpm-suite
mongoid5
pygraphviz
jslider
lfe
mixed-models
irr
chrome-custom-tabs
weld
hierarchical-clustering
audio-fingerprinting
dynamic-linking
aws-rds
x12
disconnect
rowname
cherry-pick
weblogic-maven-plugin
angular-i18n
3d-rendering
window.location
cexception
periodic-processing
google-app-engine-php
encode
log4cxx
pushwoosh
hexagonal-tiles
joomla3.3
strcpy
sony-xperia
qf-test
gnip
selenium-grid2
visual-studio-setup-proje
ant-contrib
sendy
windows-phone-store
php-amqplib
nop
ekevent
svg-android
thucydides
google-voice
pechkin
nsnumber
nx
screensharing
gssapi
junit-rule
webpage-screenshot
blackberry-eclipse-plugin
jmesa
jqzoom
mscorlib
peoplepicker
funambol
response-time
mass-emails
rollover
database-agnostic
webdb

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