C
C#2y ago
:

✅ Foreign key not working

Hi, I tried making a foreign key in my table, to another table which I made but it does not work as intended.
[ForeignKey("FileName")]
public Guid FileName { get; set; }
public TextFileModel TextFileModel { get; set; }
[ForeignKey("FileName")]
public Guid FileName { get; set; }
public TextFileModel TextFileModel { get; set; }
I tried making a filename field which is a fk to a textfilemodel, but it has instead made two separate fields:
11 Replies
Patrick
Patrick2y ago
because by convention your nav prop should be the same as the FK
:
:2y ago
So it has to be TextFileModel?
Patrick
Patrick2y ago
is FileName the FK for TextFileModel?
:
:2y ago
Yeah I tried this and it seems to have worked
Patrick
Patrick2y ago
public Guid TextFileModelId { get; set; }
public TextFileModel TextFileModel { get; set; }
public Guid TextFileModelId { get; set; }
public TextFileModel TextFileModel { get; set; }
:
:2y ago
Alright I have another question, in my textfilemodel I have two foreign keys to the asp.net user table, and for some reason they allow nulls even though I did not specify for them to
:
:2y ago
:
:2y ago
//Author

[ForeignKey("UserId")]
public string AuthorId { get; set; }

public IdentityUser Author { get; set; }


//LastEditedBy

[ForeignKey("UserId")]
public string LastEditedById { get; set; }

public IdentityUser LastEditedBy { get; set; }
//Author

[ForeignKey("UserId")]
public string AuthorId { get; set; }

public IdentityUser Author { get; set; }


//LastEditedBy

[ForeignKey("UserId")]
public string LastEditedById { get; set; }

public IdentityUser LastEditedBy { get; set; }
and thats the code
Patrick
Patrick2y ago
because strings are nullable by default [Required]
:
:2y ago
Alright, thanks!
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server
More Posts
✅ Shorten data querying lineHi, how do I shorten this line that's querying for data? Like, instead of putting them into one long❔ Blazor JS Interop - Return RTCPeerConnection from js to Blazor in order to close itHi, I've quite a complex task: In my Blazor application I use javascript to read webrtc data produce✅ Authentication with CookiesI'm playing around with cookies to get a better understanding. My code: ``` var builder = WebApplic❔ need help with visual studio communityhi i have multipul q 1- i have mac is there way to have community on it 2- please hoe to make 3 buUsing the new INumber interface to determine if an object is a number without having the generic argWith .net7 we now have the INumber<TSelf> interface which is pretty cool, and I thought I found a pl✅ Polyphormism?Is this polyphornism? I am not sure, I was told I should make something like this ```cs public abst❔ I'm not sure what's wrong with my codeI don't know why Thompson still pop up only T should be. (The blue outline is what I'm trying to do)✅ WPF Build size triples after changing target framework to net6.0-windows10.0.17763.0Hello. My WPF application uses .net6 and recently I was asked to use 'toast' style Windows 10/11 notASP Web-API with MessageBroker - Post was processed, what now?I'm trying to seperate the ASP Web-API from the workers which interact with the daterbase using Rabb✅ Trying to display a string backwards and lower caseAnd I don't understand on how to use Reverse() method