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

in nested root node how to delete one node particularly
Signalr 2 disconnects on method to ListAll in table, but can insert into table with Create method
parse file in C# with Regex and search lines
adding new property to asp.net identity role [duplicate]
Remove label for in div
Email confirmation link using office 365 in ASP.NET MVC [duplicate]
Calculate the size of a shadow
Call a web service from a desktop application in c#
Get members of custom class to read their values
Dynamically include/exclude fields in where clause LINQ
How do I send an Email using c#?
visual studio 2015 the following error occurred attempting to run the project model server process(1.0.3)
Stored procedure OUTPUT VARCHAR2 value truncated using 12c client
LINQ to Entities does not recognize the method 'System.String ToString(System.String)
How to get from a hashset all the elements that are of a particular subclass in c#?
enforce the DirectShow to select my video device via lan

Categories

HOME
pact
swift3
readdir
skypedeveloper
conceptual
nltk
procmon
schema
pdf-generation
cdn
samsung-gear-s2
promotions
yacc
ionic-native
subprocess
phpexcel
oms
jcodemodel
camunda
jsfiddle
bookmarklet
openscad
jquery-easyui
wallet
indri
caldav
sonarlint
datasource
gomobile
devexpress-mvc
policy
utc
large-files
azure-table-storage
semantic-ui-react
apm
visual-studio-debugging
unity3d-5
jsonapi-resources
webspeech-api
fastadapter
ponylang
abide
stochastic-process
stdin
nscollectionview
niagara-ax
ocamlbuild
spring-webflow-2
google-chrome-storage
geminabox
trusted-computing
git-cherry-pick
android-xmlpullparser
system-integration
transaction-isolation
methodology
wonderware
web-performance
transbase
edgar
android-togglebutton
dnvm
cloud-storage
euro
web-standards
maven-archetype
mind-manager
breeze-sharp
system.net
powershell-v1.0
isl
sendy
rssi
object-oriented-database
nop
complete
code-complete
aspnet-compiler
objectdatasource
spawn
cloudmade
nx
zepto
idoc
linear-interpolation
motordriver
hypertable
visual-leak-detector
designated-initializer
norton
javah
rollover
pitch-shifting
system-analysis
hp-trim
atmega16
onresize
managed-code
stackless

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