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

Array of Lists throws NullReferenceException
Nhibernate session management strategy for web application with background-workers?
Matching failed messages to their exceptions in NServiceBus using MSMQ
dependency properties in Silverlight
Shallow vs. Deep Copies in Immutable Objects
Recognize if the client is requesting page or something else in ASP.NET MVC custom HttpModule?
NHibernate: Prevent Refresh to trigger uninitialized Collections
Microsoft.Office.Interop.Word “Cannot activate application”
“The post's links must direct to the application's connect or canvas url”?
Dotnet :- How to make Autocomplete textbox search case insensitive?
C# thread functions not properly sharing a static data member
Problem passing object between WCF and ASMX using DataContracts
jqGrid row update
How do I add a number to a label in C#?
How to use a c# method in a sql stored procedure
Make text to have background + border

Categories

HOME
asp.net
logging
gulp
redux
cors
weblogic
apache-storm
data-modeling
pip
restheart
soap-client
ios-universal-links
runtime
spring-data-solr
velocity
decoding
websharper
tracking
jinja2
passbook
minimagick
git-branch
ejb-3.1
cherrypy
coccinelle
ithit-webdav-server
symlink
visual-studio-community
bytebuffer
sphinx4
pushpad
2checkout
intermec
imdb
kubectl
directions
contextmenustrip
microstrategy
restler
mybatis-generator
uitextview
superclass
amazon-fire-tv
rivets.js
evaluation
bioperl
photoshop-script
jenkins-docker
trusted-computing
portaudio
alarmmanager
toggleclass
mate-desktop
cosign-api
clique
skbio
apache2-module
maven-antrun-plugin
database-project
jts
tooltwist
teamwork
nsq
azure-worker-roles
disparity-mapping
webshim
html5-filesystem
git-subtree
google-voice
misfire-instruction
kendo-window
ojb
zend-db-table
typography
mandelbrot
wpd
wordbreaker
msbuild-task
string-length
urlfetch
algol
mail-gem
sqlbuddy
utm
noise-reduction
oaw
dongle
silverlight-2.0
linq-to-mysql
uccapi
time-management
script-tag
atmega16
opengl-to-opengles
file-icons
hotfix

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile