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

Activities of "fguo"

I am studying the Documents/Developing-Step-By-Step-Angular. The GetPeopleInput class contains only one string type filter, and the Angular UI adds a string value as a parameter in url. In my application, the search criteria contain multiple filters like a complex object. For example:

criteriaObj: { filter1: string, filter2: date, filter3: [ {}, {} ] }

I wonder what is the best practice to handle such filter object in ASP.NET Zero projects? Do you have an example about it?

Thanks,

My fault! I forgot to add constructor in AppService class. I fixed it and it works as expected. :D

I only test GET on this point, and still have a little concern about POST and PUT, because the database table has no such automatically generated columns (e.g. CreationTime, CreatorUserId, DeletionTime, DeleterUserId, IsDeleted, and so on). While POST or PUT, I am afraid it will try to add values into these not-existing columns and cause errors.

Is it possible to happen? I will continue to test.

Thanks,

After making those changes, there is no error on compile time, but there is a warning on "_customerRepository", said it "is never assigned to, and will always have its default value null."

I tried same thing as you instructed:

Let MyEntity inherit from Abp.Domain.Entities.Entity class, Map Id field of my entity to SCM_ID by adding the code into onModelCreating of the DbContext.

But it still has a run time error around the line: private readonly IRepository<Customer> _customerRepository;

The “_customerRepository” seems never assigned to and always null.

Do you mean I have to remove "IRepository<Customer>", and build my own Repository class?

Thanks,

I need to create an entity with an existing table, so I have to use the existing column name, especially the prime key column. That means I cannot inherit the FullAuditedEntity, otherwise, it will add a key column “Id” and other predefined columns. The problem happens while I create the AppService on the IRepository<TEntity>. It seems that the TEntity must inherit the FullAuditedEntity. Otherwise, there is a compile error:

There is no implicit reference conversion from ‘Custom-Type’ to ‘Abp.Domain.Entities.IEntity<int>’.

Here is my sample code for Entity. The table “Customers” is an existing table with a prime key “SCM_ID”. I have to remove the “FullAuditedEntity”:

[Table("Customers")]
public class Customer //: FullAuditedEntity
{
    public const int MaxNameLength = 32;

    [Required]
    [Key]
    public int SCM_ID { get; set; }

    [MaxLength(MaxNameLength)]
    public virtual string SCM_Name { get; set; }
}

Here is my sample code for AppService:

public class CustomerAppService : MyAppServiceBase, ICustomerAppService
{
    private readonly IRepository&lt;Customer&gt; _customerRepository; //ERRORS HERE!!

    public ListResultDto&lt;CustomerListDto&gt; GetCustomers(GetCustomersInput input)
    {
        var customers = _customerRepository
            .GetAll()
            .ToList();

        return new ListResultDto&lt;CustomerListDto&gt;(ObjectMapper.Map&lt;List&lt;CustomerListDto&gt;>(customers));
    }
}

The compile error is on the line of “IRepository<Customer>”:

The type ‘…Customer’ cannot be used as type parameter ‘TEntity’ in the generic type or method ‘IRepository<TEntity>’. There is no implicit reference conversion from ‘…Customer’ to ‘Abp.Domain.Entities.IEntity<int>’

I tried to force the Entity and the ListDto class to inherit the “FullAuditedEntity”. It can pass the compile, but it has an error on run-time: the “_customerRepository” seems never assigned to and always null.

Please advise a correct way for entities with existing database table.

Thanks,

Do you mean to use a parameter "-ConfigurationTypeName"? I used a command as:

Add-Migration "Added_Customers_Table" -Context "App1DbContext" -ConfigurationTypeName "App1DbContextConfigurer"

That is wrong. "A parameter cannot be found that matches parameter name 'ConfigurationTypeName'".

The above "App1DbContextConfigurer" is the class name for the new DbContext:

public static class App1DbContextConfigurer { public static void Configure(DbContextOptionsBuilder<App1DbContext> builder, string connectionString) { builder.UserSqlServer(connectionString); } }

Can you give me the exact Add-Migration command?

I cloned it to my local machine and studied it. It seems for “Boilerplate” users, instead of Prime users. To implement the same concept into ASP.NET Zero project, I tried the following steps, but it failed :( . Let me describe it step-by-step as following, and hope you can tell me what I missed.

  1. In .Web.Host project, appsettings.json, add another ConnectionString: “App1” with same value of “Default”.
  2. In .Core project, Costs.cs, add a const: public const string ConnectionStringName1 = "App1";
  3. In .EntityFrameworkCore project, create a new folder: App1EntityFrameworkCore.
  4. Copy all files in EntityFrameworkCore folder into App1EntityFrameworkCore folder, and replace the file name prefix with “App1”, so new files named as App1xxx.cs.
  5. Set new namespace ProjecrtName.App1EntityFrameworkCore in all new copied files.
  6. Change all “DbContext” words to “App1DbContext” in all new copied files.
  7. Change ConnectionStringName to ConnectionStringName1 in App1DbContextFactory.cs.
  8. Build and run successfully without compile error.

Then, I tried to connect an existing table “Customers” in another database with “App1” connectionString:

  1. In .Core project, I added a file: App1\Customer\Customer.cs. It contains a class [Table("Customers")] public class Customer: FullAuditedEntity { [Required] [MaxLength(200)] public virtual string SCM_Name { get; set; } // It is an existing column name. }

  2. In App1DbContext.cs file, I cleaned old code and added new code as below: public class App1DbContext : AbpZeroDbContext<Tenant, Role, User, App1DbContext> { public virtual DbSet<Customer> Customers { get; set; } public App1DbContext(DbContextOptions<App1DbContext> options) : base(options) { } }

  3. I tried to add migration to see if this new table can be created (I am not going to update database). I run Add-Migration "Added_Customers_Table", but it prompts me “More than one DbContext was found.” So I run as Add-Migration "Added_Customers_Table" -Context "App1DbContext". It generated a class Added_Customers_Table, but it does not contain the creation of new table. Instead, it contains many tables, just same as “Initial_Migration” class. :?: :?: I think something wrong from this point.

  4. I continue to add a service “GetCustomers” and it successfully added on Swagger as /api/services/app/CustomerService/GetCustomers. But, the Unit test failed, and if I directly run localhost:22742/api/services/app/CustomerService/GetCustomers, I got “internal error”: {"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}

I lost here. Please advise how to implement “Multiple Database” in ASP.NET Zero project.

Thanks,

Can I clone/download your example from git?

Thanks,

I am following "Developing-Step-By-Step-Angular" to add my own application. I want to keep all built-in functions in "default" database and store my own application data in a separated database.

I added another ConnectionString in appsettings.json, like { "ConnectionStrings":{"Default": "//default string", "AppData":"//application string"}, ......}

I wonder what is the best practice to use the separated connection "AppData". For example in "Creating Person Entity" step, how do I reference the connectionString to create [Table("PbPersons")] into "AppData" database?

Actually, the "AppData" database and tables exist already. I don't need to migrate/seed. I just need to map the schema from existing table to Person entity. Please advise!

Thanks,

Understand now. Thank you very much! :D

Showing 191 to 200 of 254 entries