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

What is recommended way to compare ReflectionOnlyType with Type?
Easiest way to create a Regex with multiple scenario
How do I display “Android backspace” - ⌫ in Label
ASP.NET Web API 2 - error 400 response cached?
XAML AdMediator windows 10 configuration - nothing I do shows the ad.
Bind HashSet to DataGridView DataSource C#
c# client-server using UDP Connection
Error when using Lidgren Gen3 in Unity3d
How to display a signed three bytes hexadecimal output in C#?
C# How to send a 1GB file using TCP client
Unable to sort List
TimeSetEvent failing after a few seconds (NullReferenceException)
Recording Audio and Playing sound at the same time - C# - Windows Phone 8.1
No overload for method 'query' takes 5 arguments salesforce
How to bind Func<T,T,T> to dependency property in XAML from view model?
Connection must be open C#

Categories

HOME
joomla
model-view-controller
qemu
snappy
grpc
highmaps
spotfire
ms-application-insights
sms
snmp
schema
pdf-generation
handlebars.js
samsung-gear-s2
promotions
angularjs-ng-repeat
openbsd
point-of-sale
jetbrains
cakephp-2.0
comma
github-flavored-markdown
luis
simd
powerpivot
ibatis
android-actionbar
geography
xforms
bootstrap-datetimepicker
fastboot
datastax-enterprise
datanucleus
rollupjs
android-cursorloader
cloudformation
angular2-changedetection
typeorm
git-submodules
spock
ipython-parallel
intermec
wordpress-rest-api
choco
pymunk
azure-vm-scale-set
mkdir
maven-2
rythm
form-fields
lfe
ssdp
wicket-tester
serverless-architecture
easyquery
activesupport
seyren
r-commander
totalview
scanf
esprima
blitz3d
timefield
distcc
virtualenvwrapper
tinybox2
netlink
geokit
change-password
android-xmlpullparser
django-celery
chomsky-normal-form
alchemy
dynamics-nav
imageicon
sdkman
updating
personality-insights
jain-sip
tooltwist
pagecontrol
sparkcore
jeet-grid
wingdb
method-overloading
im4java
xts
ccmenuitem
triplestore
step
scjp
codio
mysql-error-1146
grunt-wiredep
tlbimp
mosix
pudb
bho
cron4j
orchestration
mvcmailer
facebook-winjs-sdk
capitalization
umfpack
hs-err
cinder
file-storage
disk-based

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App