Multiple item in object
up vote
0
down vote
favorite
c# : EF Relation
.net core
Good Afternoon
I'm trying to create service for Dietician.
I want to made Db that allow :
One diet can have multiple Meal but
one Meal can be at multiple diet
now i has
public class DietList
{
public Guid DietListId { get; set; }
[Display(Name = "Nazwa diety")]
public string DietName { get; set; }
public DateTime AddedDataTime { get; set; }
public string Describe { get; set; }
public List<Meal> MealId { get; set; }
}
and
public class Meal
{
public Guid MealId { get; set; }
[Display(Name = "Nazwa Posiłku")]
public string MealName { get; set; }
[Display(Name = "Typ Posiłku")]
public string MealType { get; set; }
[Display(Name = "Składniki")]
public string Components { get; set; }
public List<DietList> DietListId { get; set; }
}
but it throw exception :
Unable to determine the relationship represented by navigation property 'DietList.MealId' of type 'List'.
Any solve of this problem ?
c# sql database entity-framework asp.net-core
|
show 5 more comments
up vote
0
down vote
favorite
c# : EF Relation
.net core
Good Afternoon
I'm trying to create service for Dietician.
I want to made Db that allow :
One diet can have multiple Meal but
one Meal can be at multiple diet
now i has
public class DietList
{
public Guid DietListId { get; set; }
[Display(Name = "Nazwa diety")]
public string DietName { get; set; }
public DateTime AddedDataTime { get; set; }
public string Describe { get; set; }
public List<Meal> MealId { get; set; }
}
and
public class Meal
{
public Guid MealId { get; set; }
[Display(Name = "Nazwa Posiłku")]
public string MealName { get; set; }
[Display(Name = "Typ Posiłku")]
public string MealType { get; set; }
[Display(Name = "Składniki")]
public string Components { get; set; }
public List<DietList> DietListId { get; set; }
}
but it throw exception :
Unable to determine the relationship represented by navigation property 'DietList.MealId' of type 'List'.
Any solve of this problem ?
c# sql database entity-framework asp.net-core
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
3
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link yourDietList
andMeal
instances.
– vinicius.ras
Nov 22 at 18:01
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
c# : EF Relation
.net core
Good Afternoon
I'm trying to create service for Dietician.
I want to made Db that allow :
One diet can have multiple Meal but
one Meal can be at multiple diet
now i has
public class DietList
{
public Guid DietListId { get; set; }
[Display(Name = "Nazwa diety")]
public string DietName { get; set; }
public DateTime AddedDataTime { get; set; }
public string Describe { get; set; }
public List<Meal> MealId { get; set; }
}
and
public class Meal
{
public Guid MealId { get; set; }
[Display(Name = "Nazwa Posiłku")]
public string MealName { get; set; }
[Display(Name = "Typ Posiłku")]
public string MealType { get; set; }
[Display(Name = "Składniki")]
public string Components { get; set; }
public List<DietList> DietListId { get; set; }
}
but it throw exception :
Unable to determine the relationship represented by navigation property 'DietList.MealId' of type 'List'.
Any solve of this problem ?
c# sql database entity-framework asp.net-core
c# : EF Relation
.net core
Good Afternoon
I'm trying to create service for Dietician.
I want to made Db that allow :
One diet can have multiple Meal but
one Meal can be at multiple diet
now i has
public class DietList
{
public Guid DietListId { get; set; }
[Display(Name = "Nazwa diety")]
public string DietName { get; set; }
public DateTime AddedDataTime { get; set; }
public string Describe { get; set; }
public List<Meal> MealId { get; set; }
}
and
public class Meal
{
public Guid MealId { get; set; }
[Display(Name = "Nazwa Posiłku")]
public string MealName { get; set; }
[Display(Name = "Typ Posiłku")]
public string MealType { get; set; }
[Display(Name = "Składniki")]
public string Components { get; set; }
public List<DietList> DietListId { get; set; }
}
but it throw exception :
Unable to determine the relationship represented by navigation property 'DietList.MealId' of type 'List'.
Any solve of this problem ?
c# sql database entity-framework asp.net-core
c# sql database entity-framework asp.net-core
edited Nov 22 at 17:36
asked Nov 22 at 17:28
Systu
127
127
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
3
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link yourDietList
andMeal
instances.
– vinicius.ras
Nov 22 at 18:01
|
show 5 more comments
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
3
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link yourDietList
andMeal
instances.
– vinicius.ras
Nov 22 at 18:01
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
3
3
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link your
DietList
and Meal
instances.– vinicius.ras
Nov 22 at 18:01
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link your
DietList
and Meal
instances.– vinicius.ras
Nov 22 at 18:01
|
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Based on your description, you have a many-to-many relationship between Diet
and Meal
.
It needs an extra/middle table to store the linkage of entities, say DietMeals
.
Then you can specify the relationship in the DbContext
class.
You can refer to this article.
The property naming looks a little bit confusing. The collection name should in plural form, say:
Public List<Meal> Meals { get; set; }
add a comment |
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',
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%2f53435851%2fmultiple-item-in-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Based on your description, you have a many-to-many relationship between Diet
and Meal
.
It needs an extra/middle table to store the linkage of entities, say DietMeals
.
Then you can specify the relationship in the DbContext
class.
You can refer to this article.
The property naming looks a little bit confusing. The collection name should in plural form, say:
Public List<Meal> Meals { get; set; }
add a comment |
up vote
3
down vote
accepted
Based on your description, you have a many-to-many relationship between Diet
and Meal
.
It needs an extra/middle table to store the linkage of entities, say DietMeals
.
Then you can specify the relationship in the DbContext
class.
You can refer to this article.
The property naming looks a little bit confusing. The collection name should in plural form, say:
Public List<Meal> Meals { get; set; }
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Based on your description, you have a many-to-many relationship between Diet
and Meal
.
It needs an extra/middle table to store the linkage of entities, say DietMeals
.
Then you can specify the relationship in the DbContext
class.
You can refer to this article.
The property naming looks a little bit confusing. The collection name should in plural form, say:
Public List<Meal> Meals { get; set; }
Based on your description, you have a many-to-many relationship between Diet
and Meal
.
It needs an extra/middle table to store the linkage of entities, say DietMeals
.
Then you can specify the relationship in the DbContext
class.
You can refer to this article.
The property naming looks a little bit confusing. The collection name should in plural form, say:
Public List<Meal> Meals { get; set; }
edited Nov 23 at 2:07
fuzz
15.1k17108183
15.1k17108183
answered Nov 23 at 1:50
Pegasus
463
463
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53435851%2fmultiple-item-in-object%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
is the dotnet core or .Net Framework?
– Sam
Nov 22 at 17:33
There is not enough info but I think you need to change the names of your navigation property.
– Llazar
Nov 22 at 17:34
it's a .net core im added information about that
– Systu
Nov 22 at 17:36
Yes, change your names from MealId -> MealList and DietListId -> DietList. That may not be your issue, but it makes it clearer. Also, any fluent code?
– Steve Greene
Nov 22 at 17:38
3
If you are using Entity Framework Core, you cannot model Many-to-many relationships without an intermediate table. Read these docs for more information. You would have to create a model class to link your
DietList
andMeal
instances.– vinicius.ras
Nov 22 at 18:01