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

WCF Callback failing due to object not being initialized (Duplex)
Getting info from currently running unit test
How can you set an entire object using LINQ to SQL?
Can the Garbage Collection in C# find and remove internal linked classes only? [duplicate]
dynamically work with different classes
LINQ .ToDictionary for 2d dictionary
how to convert regex match to integer? (returns “Input string was not in a correct format”)
C# type-casting sender
Retaining Indentation of the list after adding to PdfCell
How does one declare a scalar variable?
C# How To Simulate Ruzzle Gestures
Getting Thread Abort Exception while using Response.Redirect()
How to update the progress bar through Backgroundworker in C#? [duplicate]
How to use Ternary operation for Linq insertion from form Correctly
get first item on certain dropdown list and all from listbox using jquery
Nikon sdk c# wrapper-capture live pics

Categories

HOME
asp.net
grizzly
stata
sql-server-2014
network-programming
qemu
dronekit
aix
arcgis
hex
ubuntu-14.04
crash
ms-application-insights
sms
css-selectors
cdn
jquery-select2
browserstack
revit-api
software-collections
theory
fetch
expo
lambda-calculus
aggregate
box2d
owncloud
bootstrap-datetimepicker
polybase
angular2-pipe
oracle10g
adobe-captivate
spock
units-of-measurement
drawrect
textview
webmock
bootcamp
incapsula
wit-ai
asp.net-webhooks
ragel
jvisualvm
uitextview
wufoo
niagara-ax
monaca
spring-cloud-aws
scrollmagic
directinput
indoor-positioning-system
key-value-store
hoare-logic
angularfire
mod
clique
bbedit
android-progressbar
fadein
matlab-engine
libgcrypt
updating
borland-c++
vensim
page-refresh
minko
maven-archetype
bungeecord
douglas-peucker
crystal-reports-7
frisby.js
register-allocation
breeze-sharp
nodeunit
dayofweek
html5-filesystem
netbeans-plugins
myrrix
mobile-robots
playing-cards
extensibility
outlook-object-model
msbuild-task
vline
quit
custom-cursor
jquery-ui-map
flatten
scsf
mismatch
n2
noise-reduction
http-response-codes
fxcopcmd
subdirectories
helios
hp-trim
projectgen
html-help-workshop
unauthorized

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile