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

Generic method with generic interface
Convert DateTime.Now.AddDays(-30) to a unix timestamp using C# [duplicate]
Transfering Recieved Serial Port Data
chat messaging server c#
Return derived type from base class method
reading and manipulating a textfile with HTTPGET
How to specify ExpirationTime for SchedulePublish in MassTransit
Nhibernate QueryOver helper for date range without passing field name
Far Clipping Planes value doesn't change
What is the most esy way to know if an object is moving? [closed]
ProgressBar Xamarin Forms not updating
How to add a new entity marked with [DatabaseGenerated(DatabaseGeneratedOption.None)]
Invalid attempt to call Read when reader is closed while using dapper
Get Json Object From QueryString c#
500 internal error with PayPal chained payments
.Compute for Standard Deviation

Categories

HOME
spring-boot
repository
pyspark
ssh
readdir
lithium
squeak
thermal-printer
cdn
clip-path
jcodemodel
wowza
hdf5
saucelabs
aggregate
background-image
dat.gui
multibinding
google-street-view
jq
bug-reporting
devexpress-mvc
functional-dependencies
sha
jira-zephyr
nsopenpanel
windows-mobile
undo
intermec
boost-log
ilog
restler
matlab-compiler
wit-ai
headphones
javafxports
instances
file-conversion
tapply
bzip2
contenteditable
pyopenssl
lucee
activesupport
cc
rmq
suitesparse
recursive-query
gevent
toggleclass
cosign-api
sprockets
django-taggit
salesforce-service-cloud
custom-build-step
sqldataadapter
controlpanel
javapackager
android-filterable
borland-c++
tokudb
vectordrawable
grails-3.0.9
esb-toolkit-2.1
parseexception
teamstudio-unplugged
shunting-yard
jsonschema2pojo
illegalargumentexception
novell
register-allocation
octokit
caroufredsel
violation
azure-scheduler
brew
tasklist
socketasynceventargs
cgaffinetransform
soapexception
onunload
virtual-destructor
table-valued-parameters
glassfish-embedded
asp.net-1.1

Resources

Encrypt Message