one-to-one

Is there ever a time where using a database 1:1 relationship makes sense?

血红的双手。 提交于 2019-11-26 04:59:40
问题 I was thinking the other day on normalization, and it occurred to me, I cannot think of a time where there should be a 1:1 relationship in a database. Name:SSN? I\'d have them in the same table PersonID:AddressID? Again, same table. I can come up with a zillion examples of 1:many or many:many (with appropriate intermediate tables), but never a 1:1. Am I missing something obvious? 回答1: A 1:1 relationship typically indicates that you have partitioned a larger entity for some reason. Often it is

One to one optional relationship using Entity Framework Fluent API

非 Y 不嫁゛ 提交于 2019-11-26 03:08:40
问题 We want to use one to one optional relationship using Entity Framework Code First. We have two entities. public class PIIUser { public int Id { get; set; } public int? LoyaltyUserDetailId { get; set; } public LoyaltyUserDetail LoyaltyUserDetail { get; set; } } public class LoyaltyUserDetail { public int Id { get; set; } public double? AvailablePoints { get; set; } public int PIIUserId { get; set; } public PIIUser PIIUser { get; set; } } PIIUser may have a LoyaltyUserDetail but

Hibernate: one-to-one lazy loading, optional = false

百般思念 提交于 2019-11-26 02:29:25
问题 I faced the problem that one-to-one lazy loading doesn\'t work in hibernate. I\'ve already solved it , but still don\'t properly understand what happens. My code ( lazy loading doesn\'t work here , when I pull Person - Address is also fetched): @Entity public class Person{ @Id @SequenceGenerator(name = \"person_sequence\", sequenceName = \"sq_person\") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = \"person_sequence\") @Column(name = \"id\") private long personID; @OneToOne

How to Create a real one-to-one relationship in SQL Server

醉酒当歌 提交于 2019-11-26 02:20:01
问题 I have two tables tableA and tableB , I set tableB \'s primary key as foreign key which references tableA \'s primary. But when I use Entity Framework database-first, the model is 1 to 0..1. How does one create a one-to-one relationship in SQL Server? 回答1: I'm pretty sure it is technically impossible in SQL Server to have a True 1 to 1 relationship, as that would mean you would have to insert both records at the same time (otherwise you'd get a constraint error on insert), in both tables,