Click here to Skip to main content
15,914,642 members
Home / Discussions / C#
   

C#

 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
Richard Deeming27-Mar-23 0:35
mveRichard Deeming27-Mar-23 0:35 
You can't use the same collection navigation property to represent the requests where the user is the sender and the requests where the user is the target.

You also can't use the RequestId property as the foreign key to the users table - you're not creating a one-to-one relationship, so the request ID and the user ID will be different.
C#
public class User
{
    ...
    public List<Request> SentRequests { get; set; }
    public List<Request> ReceivedRequests { get; set; }
    ...
}

...

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Request>()
                .HasOne(m => m.SenderUserRef)
                .WithMany(t => t.SentRequests)
                .OnDelete(DeleteBehavior.Restrict);

    modelBuilder.Entity<Request>()
                .HasOne(m => m.TargetUserRef)
                .WithMany(t => t.ReceivedRequests)
                .OnDelete(DeleteBehavior.Restrict);
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionHow to highlight all rows in listbox between two index values? Pin
Member 1405587917-Mar-23 1:25
Member 1405587917-Mar-23 1:25 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
Pete O'Hanlon17-Mar-23 1:33
mvePete O'Hanlon17-Mar-23 1:33 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
RedDk17-Mar-23 6:26
RedDk17-Mar-23 6:26 
QuestionMessage Closed Pin
15-Mar-23 20:32
Sivanujan Sivaraja15-Mar-23 20:32 
AnswerRe: Serial port listening application Pin
OriginalGriff15-Mar-23 21:02
mveOriginalGriff15-Mar-23 21:02 
GeneralRe: Serial port listening application Pin
Richard MacCutchan15-Mar-23 22:34
mveRichard MacCutchan15-Mar-23 22:34 
GeneralRe: Serial port listening application Pin
OriginalGriff15-Mar-23 22:41
mveOriginalGriff15-Mar-23 22:41 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 0:19
mvePete O'Hanlon16-Mar-23 0:19 
GeneralRe: Serial port listening application Pin
OriginalGriff16-Mar-23 1:17
mveOriginalGriff16-Mar-23 1:17 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 6:11
mvePete O'Hanlon16-Mar-23 6:11 
GeneralRe: Serial port listening application Pin
Dave Kreskowiak16-Mar-23 6:21
mveDave Kreskowiak16-Mar-23 6:21 
QuestionDownloading & Executing an Installer - User Cancels Pin
Kevin Marois13-Mar-23 12:52
professionalKevin Marois13-Mar-23 12:52 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Dave Kreskowiak13-Mar-23 17:43
mveDave Kreskowiak13-Mar-23 17:43 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Graeme_Grant14-Mar-23 5:39
mvaGraeme_Grant14-Mar-23 5:39 
AnswerRe: Downloading & Executing an Installer - User Cancels Pin
Alan N14-Mar-23 10:00
Alan N14-Mar-23 10:00 
GeneralRe: Downloading & Executing an Installer - User Cancels Pin
Kevin Marois14-Mar-23 11:15
professionalKevin Marois14-Mar-23 11:15 
QuestionLooking to hire a programmer Pin
Thomas Matson10-Mar-23 6:33
Thomas Matson10-Mar-23 6:33 
AnswerRe: Looking to hire a programmer Pin
OriginalGriff10-Mar-23 6:34
mveOriginalGriff10-Mar-23 6:34 
GeneralRe: Looking to hire a programmer Pin
Thomas Matson10-Mar-23 6:46
Thomas Matson10-Mar-23 6:46 
GeneralRe: Looking to hire a programmer Pin
Graeme_Grant14-Mar-23 5:20
mvaGraeme_Grant14-Mar-23 5:20 
GeneralOff topic: New icon in Reply - View Thread line in messages Pin
jsc4213-Mar-23 23:16
professionaljsc4213-Mar-23 23:16 
GeneralRe: Off topic: New icon in Reply - View Thread line in messages Pin
OriginalGriff14-Mar-23 0:15
mveOriginalGriff14-Mar-23 0:15 
GeneralRe: Off topic: New icon in Reply - View Thread line in messages Pin
jsc4214-Mar-23 4:00
professionaljsc4214-Mar-23 4:00 
AnswerRe: Looking to hire a programmer Pin
jschell10-Mar-23 11:05
jschell10-Mar-23 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.