Entity Framework Code first, relation between models












1















Is there someone who will listen to me and help me solve my problem?



I have 3 classes (Product, Lot and Rem):



Each Product has many Lot and each Lot has many Rem.



public class Product {
public int id { get; set; }
public string name { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }
}









share|improve this question




















  • 2





    What exactly is your question?

    – deHaar
    Nov 14 '18 at 15:10











  • How to modify these classes to be well connected

    – Ah Bo
    Nov 14 '18 at 15:12











  • What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

    – deHaar
    Nov 14 '18 at 15:27











  • From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

    – Tyler Sells
    Nov 14 '18 at 17:11
















1















Is there someone who will listen to me and help me solve my problem?



I have 3 classes (Product, Lot and Rem):



Each Product has many Lot and each Lot has many Rem.



public class Product {
public int id { get; set; }
public string name { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }
}









share|improve this question




















  • 2





    What exactly is your question?

    – deHaar
    Nov 14 '18 at 15:10











  • How to modify these classes to be well connected

    – Ah Bo
    Nov 14 '18 at 15:12











  • What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

    – deHaar
    Nov 14 '18 at 15:27











  • From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

    – Tyler Sells
    Nov 14 '18 at 17:11














1












1








1








Is there someone who will listen to me and help me solve my problem?



I have 3 classes (Product, Lot and Rem):



Each Product has many Lot and each Lot has many Rem.



public class Product {
public int id { get; set; }
public string name { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }
}









share|improve this question
















Is there someone who will listen to me and help me solve my problem?



I have 3 classes (Product, Lot and Rem):



Each Product has many Lot and each Lot has many Rem.



public class Product {
public int id { get; set; }
public string name { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }
}






asp.net entity-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:10









mbharanidharan88

4,05942455




4,05942455










asked Nov 14 '18 at 15:01









Ah BoAh Bo

133




133








  • 2





    What exactly is your question?

    – deHaar
    Nov 14 '18 at 15:10











  • How to modify these classes to be well connected

    – Ah Bo
    Nov 14 '18 at 15:12











  • What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

    – deHaar
    Nov 14 '18 at 15:27











  • From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

    – Tyler Sells
    Nov 14 '18 at 17:11














  • 2





    What exactly is your question?

    – deHaar
    Nov 14 '18 at 15:10











  • How to modify these classes to be well connected

    – Ah Bo
    Nov 14 '18 at 15:12











  • What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

    – deHaar
    Nov 14 '18 at 15:27











  • From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

    – Tyler Sells
    Nov 14 '18 at 17:11








2




2





What exactly is your question?

– deHaar
Nov 14 '18 at 15:10





What exactly is your question?

– deHaar
Nov 14 '18 at 15:10













How to modify these classes to be well connected

– Ah Bo
Nov 14 '18 at 15:12





How to modify these classes to be well connected

– Ah Bo
Nov 14 '18 at 15:12













What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

– deHaar
Nov 14 '18 at 15:27





What about a List<Lot> as a class member of Product as well as a List<Rem> as a class member of Lot? You would have to implement some add(Lot lot) and remove(Lot lot) if you are in need of those actions. Same for Lot and its Rems...

– deHaar
Nov 14 '18 at 15:27













From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

– Tyler Sells
Nov 14 '18 at 17:11





From Microsoft: docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/…

– Tyler Sells
Nov 14 '18 at 17:11












1 Answer
1






active

oldest

votes


















0














From what you described above this is a simple way for related entities in EF.



public class Product {
public int id { get; set; }
public string name { get; set; }

public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }

public Product ProductId {get; set; }
public Product Product {get; set; }

public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }

public Lot LotId {get; set; }
public Lot Lot { get; set; }

}


And the dbcontext class



public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}


You can find further explanation about relationships in EF from relationships in EF






share|improve this answer



















  • 1





    Thank you, it's helpful

    – Ah Bo
    Jan 13 at 22:58











  • Glad to help you @AhBo

    – Llazar
    Jan 14 at 9:18











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303126%2fentity-framework-code-first-relation-between-models%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









0














From what you described above this is a simple way for related entities in EF.



public class Product {
public int id { get; set; }
public string name { get; set; }

public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }

public Product ProductId {get; set; }
public Product Product {get; set; }

public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }

public Lot LotId {get; set; }
public Lot Lot { get; set; }

}


And the dbcontext class



public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}


You can find further explanation about relationships in EF from relationships in EF






share|improve this answer



















  • 1





    Thank you, it's helpful

    – Ah Bo
    Jan 13 at 22:58











  • Glad to help you @AhBo

    – Llazar
    Jan 14 at 9:18
















0














From what you described above this is a simple way for related entities in EF.



public class Product {
public int id { get; set; }
public string name { get; set; }

public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }

public Product ProductId {get; set; }
public Product Product {get; set; }

public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }

public Lot LotId {get; set; }
public Lot Lot { get; set; }

}


And the dbcontext class



public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}


You can find further explanation about relationships in EF from relationships in EF






share|improve this answer



















  • 1





    Thank you, it's helpful

    – Ah Bo
    Jan 13 at 22:58











  • Glad to help you @AhBo

    – Llazar
    Jan 14 at 9:18














0












0








0







From what you described above this is a simple way for related entities in EF.



public class Product {
public int id { get; set; }
public string name { get; set; }

public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }

public Product ProductId {get; set; }
public Product Product {get; set; }

public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }

public Lot LotId {get; set; }
public Lot Lot { get; set; }

}


And the dbcontext class



public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}


You can find further explanation about relationships in EF from relationships in EF






share|improve this answer













From what you described above this is a simple way for related entities in EF.



public class Product {
public int id { get; set; }
public string name { get; set; }

public Lot LotId {get; set; }
public ICollection<Lot> Lots { get; set; }
}

public class Lot {
public int id { get; set; }
public decimal price { get; set; }

public Product ProductId {get; set; }
public Product Product {get; set; }

public Rem RemId {get; set; }
public ICollection<Rem> Rems { get; set; }
}

public class Rem {
public int id { get; set; }
public string note { get; set; }

public Lot LotId {get; set; }
public Lot Lot { get; set; }

}


And the dbcontext class



public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options): base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Lot> Lots { get; set; }
public DbSet<Rem> Rems { get; set; }
}


You can find further explanation about relationships in EF from relationships in EF







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 17:58









LlazarLlazar

9581616




9581616








  • 1





    Thank you, it's helpful

    – Ah Bo
    Jan 13 at 22:58











  • Glad to help you @AhBo

    – Llazar
    Jan 14 at 9:18














  • 1





    Thank you, it's helpful

    – Ah Bo
    Jan 13 at 22:58











  • Glad to help you @AhBo

    – Llazar
    Jan 14 at 9:18








1




1





Thank you, it's helpful

– Ah Bo
Jan 13 at 22:58





Thank you, it's helpful

– Ah Bo
Jan 13 at 22:58













Glad to help you @AhBo

– Llazar
Jan 14 at 9:18





Glad to help you @AhBo

– Llazar
Jan 14 at 9:18




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303126%2fentity-framework-code-first-relation-between-models%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

The Sandy Post

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues

Fabienne KOHLMANN