Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

User related entities and navigation needs in User entity. #1729


User avatar
0
sayram created

Using FullAuditedEntity<long, User> provides Creator id. This is not actually a releationship. To store creator id if we use FullAuditedEntity we lost the Navigation in User entity. This confuses me.

Forexample:

public class Post : FullAuditedEntity<long, User> { .. }

We can access to Post's create Id. (Not name or others) Well, what if i want to get User's posts? There will be no Posts navigation in User entity. Do i have to query with creator id? Is this?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you derive from FullAuditedEntity<long, User> you should be able to access CreatorUser, does it not work for you ? You can include it in your linQ queries like this.

    _postRepository.GetAll().Include().Include(p => p.CreatorUser);
    

    or for a single entity you can use it like this

    post.CreatorUser.FullName
    

    if you want to access Posts of a user, you need to add a navigation property to User entity. in order to do that, you need to extend your User entity. <a class="postlink" href="https://aspnetzero.com/Documents/Extending-Existing-Entities">https://aspnetzero.com/Documents/Extend ... g-Entities</a>

    But in my opinion, don't do that, just query posts with creatorUserId=[someUserId],

  • User Avatar
    0
    sayram created

    <cite>ismcagdas: </cite>

    But in my opinion, don't do that, just query posts with creatorUserId=[someUserId],

    Why? Is it about performance or something else?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    No it's not related to performance actually. Almost all entities in most systems has a reference to User entity because of CreatorUserId or a similar field.

    If you follow this method (adding a navigation property for Posts to User), your User entity will have lots of navigation properties. I think this is not good practice.

    But it's your choice anyway :)