how set foreign key to multiple tablesHow do I enumerate an enum in C#?Catch multiple exceptions at once?C# How can I clear all foreign key references in order to save the deletion of the primary key record to the database?Is MySqlBulkLoader sensitive to foreign keys?Create a hierarchical foreign key to Identity 3 ApplicationUser:IdentityUserPrevent EntityFramework from setting foreign keys to nullMany to one migrations fails on foreign key longEntity Framework Core: How to solve Introducing FOREIGN KEY constraint may cause cycles or multiple cascade pathsHow to insert multiple images into MySQL database table with foreign key referencing a single primary keyError - Cannot add or update a child row: a foreign key constraint fails
What makes Ada the language of choice for the ISS's safety-critical systems?
How to produce a more sophisticated pie chart?
Playing a Character as Unobtrusive and Subservient, Yet Not Passive
Is it possible to have a wealthy country without a middle class?
How to hide an urban landmark?
How can I make some of my chapters "come to life"?
Soft question: Examples where lack of mathematical rigour cause security breaches?
Pre-1972 sci-fi short story or novel: alien(?) tunnel where people try new moves and get destroyed if they're not the correct ones
How did old MS-DOS games utilize various graphic cards?
What speaks against investing in precious metals?
Thread Pool C++ Implementation
Which languages would be most useful in Europe at the end of the 19th century?
Arriving at the same result with the opposite hypotheses
Cascading Switches. Will it affect performance?
How to safely destroy (a large quantity of) valid checks?
How to tell your grandparent to not come to fetch you with their car?
What can I, as a user, do about offensive reviews in App Store?
Bent Peugeot Carbolite 103 Frame
I have a problem assistant manager, but I can't fire him
Is using haveibeenpwned to validate password strength rational?
Geopandas and QGIS Calulating Different Polygon Area Values?
is it possible for a vehicle to be manufactured witout a catalitic converter
Meaning of 'lose their grip on the groins of their followers'
What is the purpose of the goat for Azazel, as opposed to conventional offerings?
how set foreign key to multiple tables
How do I enumerate an enum in C#?Catch multiple exceptions at once?C# How can I clear all foreign key references in order to save the deletion of the primary key record to the database?Is MySqlBulkLoader sensitive to foreign keys?Create a hierarchical foreign key to Identity 3 ApplicationUser:IdentityUserPrevent EntityFramework from setting foreign keys to nullMany to one migrations fails on foreign key longEntity Framework Core: How to solve Introducing FOREIGN KEY constraint may cause cycles or multiple cascade pathsHow to insert multiple images into MySQL database table with foreign key referencing a single primary keyError - Cannot add or update a child row: a foreign key constraint fails
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a class Articolo and a class Variante. Problem is how to configure foreign key of Stock class that refer to Articolo and Variante
My product list look so:
Article1-variante1
Article1-variante2
Article1-variante3
Article2-noVariante
...
and so on
In the Esistenze i have
Article1-variante1-5
Article1-variante2-10
Article1-variante3-100
Article2-noVariante-0
class Articolo
public string Codart get; set; //key
...
public List<Variante> Varianti get; set;
public Esistenza Esistenza get; set;
class Variante
public string Codart get; set; //key
public string Variante get; set; //key
class Esistenza
public string Codart get; set; //key
public string Variante get; set; //key
public int Esistenza get; set;
public Articolo Articolo get; set;
//sqlite
CREATE TABLE Esistenze(
[Codart] TEXT NOT NULL,
[Codvar] TEXT NOT NULL,
[Esiste] REAL NOT NULL,
CONSTRAINT [PK_Esistenze] PRIMARY KEY ( [Codart], [Codvar] ),
CONSTRAINT FK_Articoli FOREIGN KEY (Codart) REFERENCES Articoli(Codart) ON DELETE CASCADE,
CONSTRAINT FK_Varianti FOREIGN KEY (Codvar) REFERENCES Varianti(Codvar) ON DELETE CASCADE
)
public void Configure(EntityTypeBuilder<Esistenza> builder)
builder.HasKey(e => new e.Codart, e.Codvar);
builder.Property(e => e.Esiste).IsRequired();
builder
.HasOne(a => a.Articolo)
.WithOne(e => e.Esistenza)
.HasForeignKey<Esistenza>(f => new f.RkaCodart,f.RkaCodvar);
i get error
The relationship from 'Esistenza.Articolo' to 'Articolo.Esistenze' with foreign key properties 'Codart' : string, 'Codvar' : string cannot target the primary key 'Codart' : string because it is not compatible
c# entity-framework-core
add a comment |
I have a class Articolo and a class Variante. Problem is how to configure foreign key of Stock class that refer to Articolo and Variante
My product list look so:
Article1-variante1
Article1-variante2
Article1-variante3
Article2-noVariante
...
and so on
In the Esistenze i have
Article1-variante1-5
Article1-variante2-10
Article1-variante3-100
Article2-noVariante-0
class Articolo
public string Codart get; set; //key
...
public List<Variante> Varianti get; set;
public Esistenza Esistenza get; set;
class Variante
public string Codart get; set; //key
public string Variante get; set; //key
class Esistenza
public string Codart get; set; //key
public string Variante get; set; //key
public int Esistenza get; set;
public Articolo Articolo get; set;
//sqlite
CREATE TABLE Esistenze(
[Codart] TEXT NOT NULL,
[Codvar] TEXT NOT NULL,
[Esiste] REAL NOT NULL,
CONSTRAINT [PK_Esistenze] PRIMARY KEY ( [Codart], [Codvar] ),
CONSTRAINT FK_Articoli FOREIGN KEY (Codart) REFERENCES Articoli(Codart) ON DELETE CASCADE,
CONSTRAINT FK_Varianti FOREIGN KEY (Codvar) REFERENCES Varianti(Codvar) ON DELETE CASCADE
)
public void Configure(EntityTypeBuilder<Esistenza> builder)
builder.HasKey(e => new e.Codart, e.Codvar);
builder.Property(e => e.Esiste).IsRequired();
builder
.HasOne(a => a.Articolo)
.WithOne(e => e.Esistenza)
.HasForeignKey<Esistenza>(f => new f.RkaCodart,f.RkaCodvar);
i get error
The relationship from 'Esistenza.Articolo' to 'Articolo.Esistenze' with foreign key properties 'Codart' : string, 'Codvar' : string cannot target the primary key 'Codart' : string because it is not compatible
c# entity-framework-core
add a comment |
I have a class Articolo and a class Variante. Problem is how to configure foreign key of Stock class that refer to Articolo and Variante
My product list look so:
Article1-variante1
Article1-variante2
Article1-variante3
Article2-noVariante
...
and so on
In the Esistenze i have
Article1-variante1-5
Article1-variante2-10
Article1-variante3-100
Article2-noVariante-0
class Articolo
public string Codart get; set; //key
...
public List<Variante> Varianti get; set;
public Esistenza Esistenza get; set;
class Variante
public string Codart get; set; //key
public string Variante get; set; //key
class Esistenza
public string Codart get; set; //key
public string Variante get; set; //key
public int Esistenza get; set;
public Articolo Articolo get; set;
//sqlite
CREATE TABLE Esistenze(
[Codart] TEXT NOT NULL,
[Codvar] TEXT NOT NULL,
[Esiste] REAL NOT NULL,
CONSTRAINT [PK_Esistenze] PRIMARY KEY ( [Codart], [Codvar] ),
CONSTRAINT FK_Articoli FOREIGN KEY (Codart) REFERENCES Articoli(Codart) ON DELETE CASCADE,
CONSTRAINT FK_Varianti FOREIGN KEY (Codvar) REFERENCES Varianti(Codvar) ON DELETE CASCADE
)
public void Configure(EntityTypeBuilder<Esistenza> builder)
builder.HasKey(e => new e.Codart, e.Codvar);
builder.Property(e => e.Esiste).IsRequired();
builder
.HasOne(a => a.Articolo)
.WithOne(e => e.Esistenza)
.HasForeignKey<Esistenza>(f => new f.RkaCodart,f.RkaCodvar);
i get error
The relationship from 'Esistenza.Articolo' to 'Articolo.Esistenze' with foreign key properties 'Codart' : string, 'Codvar' : string cannot target the primary key 'Codart' : string because it is not compatible
c# entity-framework-core
I have a class Articolo and a class Variante. Problem is how to configure foreign key of Stock class that refer to Articolo and Variante
My product list look so:
Article1-variante1
Article1-variante2
Article1-variante3
Article2-noVariante
...
and so on
In the Esistenze i have
Article1-variante1-5
Article1-variante2-10
Article1-variante3-100
Article2-noVariante-0
class Articolo
public string Codart get; set; //key
...
public List<Variante> Varianti get; set;
public Esistenza Esistenza get; set;
class Variante
public string Codart get; set; //key
public string Variante get; set; //key
class Esistenza
public string Codart get; set; //key
public string Variante get; set; //key
public int Esistenza get; set;
public Articolo Articolo get; set;
//sqlite
CREATE TABLE Esistenze(
[Codart] TEXT NOT NULL,
[Codvar] TEXT NOT NULL,
[Esiste] REAL NOT NULL,
CONSTRAINT [PK_Esistenze] PRIMARY KEY ( [Codart], [Codvar] ),
CONSTRAINT FK_Articoli FOREIGN KEY (Codart) REFERENCES Articoli(Codart) ON DELETE CASCADE,
CONSTRAINT FK_Varianti FOREIGN KEY (Codvar) REFERENCES Varianti(Codvar) ON DELETE CASCADE
)
public void Configure(EntityTypeBuilder<Esistenza> builder)
builder.HasKey(e => new e.Codart, e.Codvar);
builder.Property(e => e.Esiste).IsRequired();
builder
.HasOne(a => a.Articolo)
.WithOne(e => e.Esistenza)
.HasForeignKey<Esistenza>(f => new f.RkaCodart,f.RkaCodvar);
i get error
The relationship from 'Esistenza.Articolo' to 'Articolo.Esistenze' with foreign key properties 'Codart' : string, 'Codvar' : string cannot target the primary key 'Codart' : string because it is not compatible
c# entity-framework-core
c# entity-framework-core
asked Mar 24 at 18:29
gigiLaTrottolagigiLaTrottola
326
326
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327094%2fhow-set-foreign-key-to-multiple-tables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327094%2fhow-set-foreign-key-to-multiple-tables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown