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,
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.
Then, I tried to connect an existing table “Customers” in another database with “App1” connectionString:
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. }
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) { } }
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.
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,
Understand now. Thank you very much! :D
The multitenancy is disabled in code MultiTenancyEnabled=false. I did this by following the instruction on "Getting Start" document. There are still two "admin" users in AbpUsers table, one with TenantId=1 and another with TenantId=null. However, I cannot login with admin whose TenantId=null.
Thank you for your improvement plan. I expect it on the next release. :)
I also added System.Net.Http 4.3.1 package to my Web.Core project and tried again. I still get same "Internal Error" popup. Here is the log text:
MailKit.Net.Smtp.SmtpProtocolException: The SMTP server has unexpectedly disconnected.
at MailKit.Net.Smtp.SmtpStream.ReadAhead(CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpStream.ReadResponse(CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
at MailKit.MailService.Connect(String host, Int32 port, Boolean useSsl, CancellationToken cancellationToken)
at Abp.MailKit.DefaultMailKitSmtpBuilder.ConfigureClient(SmtpClient client)
at Abp.MailKit.DefaultMailKitSmtpBuilder.Build()
at Abp.MailKit.MailKitEmailSender.BuildSmtpClient()
at Abp.MailKit.MailKitEmailSender.<SendAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Net.Mail.EmailSenderBase.<SendAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SNet.Authorization.Users.UserEmailer.<SendEmailActivationLinkAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinally>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.Hand...
I just tried to type something in Administration > settings > Email(SMTP) page to prevent from empty string in order to save the change. I got "Internal error" popup this time when I try to email activation. The MailKit seems handling the email but has issues around "authentication". See the log below:
System.NotSupportedException: The SMTP server does not support authentication.
at MailKit.Net.Smtp.SmtpClient.Authenticate(Encoding encoding, ICredentials credentials, CancellationToken cancellationToken)
at MailKit.MailService.Authenticate(String userName, String password, CancellationToken cancellationToken)
at Abp.MailKit.DefaultMailKitSmtpBuilder.ConfigureClient(SmtpClient client)
at Abp.MailKit.DefaultMailKitSmtpBuilder.Build()
at Abp.MailKit.MailKitEmailSender.BuildSmtpClient()
at Abp.MailKit.MailKitEmailSender.<SendAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Net.Mail.EmailSenderBase.<SendAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SNet.Configuration.SettingsAppServiceBase.<SendTestEmail>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()