abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.93k stars 3.44k forks source link

Document howto setup Relationship one-to-one,one-to-many, many-to-one, many-to-many step-by-step with examples #8513

Closed barnybadzoo closed 3 years ago

barnybadzoo commented 3 years ago

Hi,

i find it quite hard to find a suitable documentation for handling relationships between objects. In the Web-Application Tutorial we build a one-to many relationship - without navigation properties, but you suggest to use them. I need to understand howto build a database agnostic system, and how abp framework helps here (like generating needed files with abp suite)

It would be great to have a second Tutorial after the Web Application Tutorial describing building further relationships with an example for each possible Relationship like one-to-one,one-to-many, many-to-one, many-to-many . What steps are necessary within abp, entiyframework, and mongodb.

Questions to answer within this tutorial:

  Public class Network {
        public string Name { get; set; }
        public string  Ip { get; set; }
   }
  Public class Mainboard {
        public string MainboardName { get; set; }
        public List<Network> Networks { get; set; }
   }

Hope you will provide a better Documentation/ Tutorial to solve this.

gterdem commented 3 years ago

Domain Driven Design is not Abp specific. It is a desing concept. Enforcing this concept in code generation is a different topic to discuss. If you want to learn more about ddd implementation, i would like to suggest you to check Implementing Domain Driven Design.

barnybadzoo commented 3 years ago

Yes, It mostly not ABP specific, but wouldn't some details Documents help to clarify howto solve this with abp ?? I did already check the link you provided, but it doesn't answer my questions above.. When to use what, and where abp makes it easier to handle this ? As Example if i wanna change later from SQL to Mongo i should avoid navigation properties.. ABP can handle both databases.. so i should care about my design to be able to change later the database.. You should have an clearer documenation for that. (and also a simple textsearch in your documents rather than a filter, which doesn't find much)

barnybadzoo commented 3 years ago

To be really database agnostic, it would be great if you could deal at Domain Level with standard classes (poco) with every possible Types and SubClasses like above in the example, and then use an Abp Layer (or Logic) to convert them in the correct way for EntityFramework or MongoDB.. This could be done within the abp suite, which would be for a lot people a big benefit. And also this way would provide an easy change from one db to an other.

gterdem commented 3 years ago

Hi,

i find it quite hard to find a suitable documentation for handling relationships between objects. In the Web-Application Tutorial we build a one-to many relationship - without navigation properties, but you suggest to use them.

Where?

I need to understand howto build a database agnostic system, and how abp framework helps here (like generating needed files with abp suite)

I would suggest trying to understand Layer Structure. It is mostly same with Clean Architecture and Onion Architecture. Abp helps with the implementation of these layers. Abp Suite does generate base and basic layer definitions (IMyRepository, IMyAppService etc) and their implementations (MyRepository, MyAppService etc).

It would be great to have a second Tutorial after the Web Application Tutorial describing building further relationships with an example for each possible Relationship like one-to-one,one-to-many, many-to-one, many-to-many .

Abp uses EfCore, all the EfCore tutorials also applies.

What steps are necessary within abp, entiyframework, and mongodb.

Again, Abp doesn't have its own db provider and uses EfCore (sql server, postgres, oracle) and MongoDb providers. Sample Author EfCore integration documentation points out where and how to implement the repository and where to write Fluent API. And Sample Author MongoDb integration points where and how to implement the repository.

Questions to answer within this tutorial:

  • you say ddd best pratice rule: refer to other aggregates only by id). But how could i then handle something like this:
  Public class Network {
        public string Name { get; set; }
        public string  Ip { get; set; }
   }
  Public class Mainboard {
        public string MainboardName { get; set; }
        public List<Network> Networks { get; set; }
   }

In the guide i shared there is an example domain. Issue aggragate has the same relation with Comment entity. Which is pretty similar with yours. Simply add MainboardId to your Network entity (if your Mainboard is an aggragate and contains a list of network). This is completely depends on your domain design and your bounded context.

  • Should this be implemented as Class like you did in the Event Organizer, as ValueObject or as Entity ?? I did see that for every Entity a Table is created within EntiyCoreFramework, but i would like to avoid this, avoid the unnecessary joins.. All should be saved within one Table, because in this particular case its not needed to reference from elsewhere to Network.

Again, you are mixing up logical concepts with implementation blocks. Class, struct, record are just block representations for your domain implementation. Should this be a value object or an aggragate root? Who knows besides you? Maybe Julie Lerman can help.

  • Should this be a List or ICollection? (In your Event Organizer Example you did use ICollection at Domain Level and List at Application Level)

Eric Lippert doesn't think it is a bad idea to inherit concrete List, and I don't think it should be a problem to reference either. Google the difference and use whichever suits you.

  • If i extend the DbContextModelCreatingExtensions to reflect this in EntityFramework what steps are necessary for MongoDB, in generall howto approach to be database agnostic ?

When you use MongoDb; you will have a MyProjectName.MongoDB project instead of MyProjectName.EntityFrameworkCore project. DbContextModelCreatingExtensions is under EntityFrameworkCore project where you configure basically Fluent Api. In MongoDB, you don't. Your IRepository is defined in Domain Layer but it's implementation must be in done in EntityFrameworkCore project (EfCore db provider) or MongoDB project (Mongo db provider) simply because they are different dbms; one of them is relational other is no-sql.

  • Where does abp helps to automate this steps or make it easier ?

As you have followed, since it is a layered structure; you need to declare repository interfaces, service interfaces; their implemantations, dto's, mappers etc etc.. Abp Suite generates these files and basic functional code presenting you with a default UI. If your need is a simple CRUD functionality, you can already have it. If more; simply modify or create from the scratch.

Hope you will provide a better Documentation/ Tutorial to solve this.

It would be great if you point out exactly which subjects are out documentation besides the ones non-related with Abp.

gterdem commented 3 years ago

Yes, It mostly not ABP specific, but wouldn't some details Documents help to clarify howto solve this with abp ?? I did already check the link you provided, but it doesn't answer my questions above.. When to use what, and where abp makes it easier to handle this ?

There is no problem to solve. And it is completely not related with Abp. You don't have to use DDD. If you want to, you need to learn that the DDD concept is not related with programming languages or frameworks. From DDD Docs:

    ABP framework provides an infrastructure to make Domain Driven Design based development easier to implement.

How? By adding layered application model with fundemental layers. See Domain Driven Design.

As Example if i wanna change later from SQL to Mongo i should avoid navigation properties.. ABP can handle both databases.. so i should care about my design to be able to change later the database..

If you change the database provider later, you will simply need to add repository implementation and provider specific configuration. Your Domain Design stays in your Domain layer.

You should have an clearer documenation for that. (and also a simple textsearch in your documents rather than a filter, which doesn't find much)

Thanks for the feedback.

gterdem commented 3 years ago

To be really database agnostic, it would be great if you could deal at Domain Level with standard classes (poco) with every possible Types and SubClasses like above in the example, and then use an Abp Layer (or Logic) to convert them in the correct way for EntityFramework or MongoDB.. This could be done within the abp suite, which would be for a lot people a big benefit. And also this way would provide an easy change from one db to an other.

I think this question is not relevant any more.

Please check out DDD Layers docs and Abp Module Architecture docs that how Abp handles the layers to achieve database agnostic infrastructure.

barnybadzoo commented 3 years ago

First of all, thank you for your detailed response.. I am new to abp framework and yes i lack in knowledge about DDD. We did choose abp because of the features like permission system, multi-tenancy, auditing and logging etc. which we would otherwise needed to build ourselves.

You write in your tutorial:

image

This is why i tought you suggest to use navigation properties for making the code easier.. And what i meant here is, if i use navigation properties here within my domain model, i will need to redesign them later if i use mongodb. Right?

In your answer you gave me a lot of links, which i will follow and try to unterstand the design behind it.

Abp Suite generates these files and basic functional code

Yes it does, and this helps a lot. But after the Tutorial i asked myself howto proceed for collections and other relationsships. That part seems to be missing because abp suite can only handle one-to-many relationships with navigation properties. Thats why i asked for a additional tutorial. Yes, these aspects are out of scope of abp and yes this is no problem to solve here. You already provide a lot informations to ddd. From my point of view, it shouldn't be a problem to expand your Documents/Tutorial to cover the relationships like this one for example: https://www.learnentityframeworkcore.com/conventions/one-to-many-relationship, but with referencing your abp structure and files.

And one thing more to abp suite: with preview 4.3.0-rc.1 it also generates the dataseeder for the Test projects, why not also for the intialization of the project (like within the tutorial )

Its great to know, that if i want to change to mongo , i will need to add a repository implementation and provider specific files for mongo without changing my domain models. (what will be definitly the case for performance tests because we are migrating a old node/mongo solution)

(One thing i did miss is that on your documentation page at every page in the first line is a text search.. I didn't see it because i did scroll down the page -- and its not available on the left menu)

so far we will continue to use abp and get a deeper knowledge of ddd. We still evaluating it .

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.