Starts in:
2 DAYS
3 HRS
5 MIN
52 SEC
Starts in:
2 D
3 H
5 M
52 S
Open Closed

Object Extension #6363


User avatar
0
15937823 created
  • ABP Framework version: v7.3.1
  • UI Type: Angular
  • Database System: EF Core MySQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

How to query the extended fields from the database based on the input conditions of the UI after object extension? For example, adding a FullName to the organization and adding query criteria in the UI to retrieve the organization with the specified full name from the database?


16 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi,

    Have you check this doc https://docs.abp.io/en/abp/latest/Object-Extensions?

  • User Avatar
    0
    15937823 created

    Hi,

    Have you check this doc https://docs.abp.io/en/abp/latest/Object-Extensions?

    There are no extended fields in the document as query criteria to read data from the database

  • User Avatar
    0
    15937823 created

    for example:

    var query = await _organizationUnitRepository.GetQueryableAsync();

    query.WhereIf(input.FullName.IsNotNullOrWhiteSpace(), e => e.FullName.Contains(input.FullName));

    FullName is an extended field

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi,

    Please check https://docs.abp.io/en/abp/latest/Entity-Framework-Core#extra-properties-object-extension-manager and https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities

    Also have look to this https://docs.abp.io/en/abp/latest/Module-Entity-Extensions

    regards,

  • User Avatar
    0
    15937823 created

    Hi,

    Please check https://docs.abp.io/en/abp/latest/Entity-Framework-Core#extra-properties-object-extension-manager and https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities

    Also have look to this https://docs.abp.io/en/abp/latest/Module-Entity-Extensions

    regards,

    If there is one in the document, what else should I send ISSUE for?

  • User Avatar
    0
    15937823 created

    Hi,

    Please check https://docs.abp.io/en/abp/latest/Entity-Framework-Core#extra-properties-object-extension-manager and https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities

    Also have look to this https://docs.abp.io/en/abp/latest/Module-Entity-Extensions

    regards,

    Will the support team only send document links?

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi,

    You can use GetProperty & SetProperty Extension Methods for getting or setting the extra property value, this is what you expect, right? Correct me if I miss understood you.

  • User Avatar
    0
    15937823 created

    Hi,

    You can use GetProperty & SetProperty Extension Methods for getting or setting the extra property value, this is what you expect, right? Correct me if I miss understood you.

    GetProperty&SetProperty I know, do I want to use extended fields to query records in the database that meet the criteria? Do you understand?

    Do I need to redefine entity classes in the Domain layer?

  • User Avatar
    0
    15937823 created

    for example:

    var query = await _organizationUnitRepository.GetQueryableAsync();

    query.WhereIf(input.FullName.IsNotNullOrWhiteSpace(), e => e.FullName.Contains(input.FullName));

    FullName is an extended field

    There is no defined FullName field in OrganizationUnit, is FullName an extension field of OrganizationUnit? Do you understand?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    First, use the module entity extension system to add a new property to the organization. (I think you have completed this step.)

    https://docs.abp.io/en/abp/latest/Module-Entity-Extensions#quick-example

    Then, use the ef core entity extension system to make the property as a regular property in the entity

    To overcome the difficulties described above, ABP Framework entity extension system for the Entity Framework Core that allows you to use the same extra properties API defined above, but store a desired property as a separate field in the database table.

    https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities#entity-extensions-ef-core

    Then you need to add and apply migration files: dotnet ef migrations add add_fullname_to_ou, dotnet ef database update

    Now, the FullName is a shadow property, and you can access it in this way.

    var query = await _organizationUnitRepository.GetQueryableAsync();
    
    query.WhereIf(input.FullName.IsNotNullOrWhiteSpace(), e => EF.Property<string>(e, "FullName") == input.FullName);
    
  • User Avatar
    0
    15937823 created

    Hi,

    First, use the module entity extension system to add a new property to the organization. (I think you have completed this step.)

    https://docs.abp.io/en/abp/latest/Module-Entity-Extensions#quick-example

    Then, use the ef core entity extension system to make the property as a regular property in the entity

    To overcome the difficulties described above, ABP Framework entity extension system for the Entity Framework Core that allows you to use the same extra properties API defined above, but store a desired property as a separate field in the database table.

    https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities#entity-extensions-ef-core

    Then you need to add and apply migration files: dotnet ef migrations add add_fullname_to_ou, dotnet ef database update

    Now, the FullName is a shadow property, and you can access it in this way.

    var query = await _organizationUnitRepository.GetQueryableAsync(); 
     
    query.WhereIf(input.FullName.IsNotNullOrWhiteSpace(), e => EF.Property<string>(e, "FullName") == input.FullName); 
    

    Okay, I'll give it a try. The writing style is: e=>EF Property<string>(e, "FullName")==input FullName

    Thank you very much!!!

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    : )

  • User Avatar
    0
    15937823 created

    : )

    Hello, may I ask how to use Include if the extension field is a foreign key? thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You need additional queries, because entities have no navigation properties

  • User Avatar
    0
    15937823 created

    Hi,

    You need additional queries, because entities have no navigation properties

    Can you help me write an example? thank you.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Ok, for example:

    
    public class Book: ...
    {
      
    }
    
    ObjectExtensionManager.Instance
        .MapEfCoreProperty<IdentityUser, Guid>(
            "BookId",
            (entityBuilder, propertyBuilder) =>
            {
                entityBuilder.HasOne(typeof(Book), "BookId").WithOne().IsRequired(false).HasForeignKey("BookId");
            }
        );
    
    public class IdentityUserWithBook
    {
        public IdentityUser User { get; set;}
        public Book Book { get; set;}
    }
    
    
    var query = await _userRepository.GetQueryableAsync(); 
     
    var users = await query.ToListAsync();
    var bookIds = users.Select(x => x.GetProperty<Guid>("BookId")).ToList();
    var books = await _bookRepository.GetListAsync(x => bookIds.Contains(x.Id)).ToListAsync();
    
    var result = users.Select(u => new IdentityUserWithBook
            {
                User = u,
                Book = books.FirstOrDefault(b => u.GetProperty<Guid>("BookId") = b.Id)
            }).ToList();
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06