Pass in the proper connection string to UseSqlServer.
I even tried to hard-coded the connection strings, but still got SAME exception.
You know it's solved, but you refuse to use the solution?
I tried this "solution", but still got SAME exception.
Let me change an angle to state my question. I want to get the current username while inserting a record into the 2nd database. My following code throws exception:
public async Task CreateObj(ObjListDto input) { var obj = ObjectMapper.Map<Obj>(input); obj.Username = GetCurrentUser().UserName; //this line caused the exception await _objRepository.InsertAsync(obj); }
Can you give me another way to get the current username ?
Thanks,
Yes. My both DbContexts work fine, if use them separately. For example, I can get "accessToken" from /api/TokenAuth/Authenticate. The user entity is in ProjectDbContext. I can get "myEntity" from CustomDbContext.
There seems no built-in way to add multiple DbContexts for multiple databases so far. I tried the way your indicated, but it does not work for me. My CustomDbContext never connected in that way. I know I must miss something. I am still waiting for an "official" release for using multiple DbContext.
Currently, I use my own workaround. I made an "AppEntityFrameworkCoreModule" which is very similar to "ProjectEntityFrameworkCoreModule", but with different connection string. I added "typeof(App1EntityFrameworkCoreModule)" on the top of WebCoreModule, so both DbContexts can be initialized. They work fine until the issue I met today.
Here is my problem code for inserting a record into the table in the 2nd database. The "Obj" is an entity in the 2nd DbContext.
public async Task CreateObj(ObjListDto input)
{
var obj = ObjectMapper.Map<Obj>(input);
obj.Username = GetCurrentUser().UserName; //this line caused the exception
await _objRepository.InsertAsync(obj);
}
Any idea?
Just added this namespace, and passed compile, but unfortunately, it still throws the same exception.
Any idea?
Thank you for your prompt response!
I am trying to add that line into PreInitialize method of EntityFrameworkCoreModule, with 2 namespaces: using Abp.EntityFrameWorkCore.Uow; using Abp.Dependency;
but got a compile error: The non-generic method 'IAbpStartupConfiguration.ReplaceService(Type, Action)' cannot be used with type arguments.
What did I miss?
Excellent!!
I will try this way later when I handle complicated mapping case.
Thanks again!!
Nice and Neat! Thank you very much!!
However, I got two glitches:
I actually want to entity1 LEFT JOIN entity2. Your code seems just working as "inner Join". When I try your code with an empty entity2, it results an empty EntityDto. It should be an EntityDto with values of all PropertyFromEntity1 but null for all PropertyFromEntity2. I reversed the order of mapping and solved it. Is it the correct way?
Another problem is about Id. As convention, both entity1 and entity2 have field "Id". I want to keep entity1.Id as EntityDto.Id and ignore entity2.Id. When I try your code, it returns the EntityDto.Id = entity2.Id, because the last mapping is on the entity2, I think. I surely can reverse the order of mapping in this particular example to solve this issue, but generally, how do I handle if entity1 and entity2 have same name properties?
For example, if I need:
[AutoMapFrom(typeof(Entity1), typeof(Entity2))] public class EntityListDto : EntityDto { public string XYZ { get; set; } // map with Entity1.XYZ, instead of Entity2.XYZ public string ABC { get; set; } // map with Entity2.ABC, instead of Entity1.ABC }
Usually, most of properties can be auto-mapped correctly, but only few of them (such as Id, name, email ...) have this kind of issue when I map joined entities. Can you show me a correct way?
Thanks again!
.Net Framework 4.6.1.
BTW, Our SMTP on IIS is shared by several applications, so I have no too much freedom to adjust its settings. I think it is a popular scenario. Is it possible for ASPNET Zero to inherit all settings from the SMTP on host? For example, on Administration>Settings>Email (SMTP) page, if any setting value keeps blank, use the value on SMTP host by default.
Thank you!
I just updated it to ngx-bootstrap v1.9.3, and solved all of the issues. :o
Just run it again and watch the browser console. There is an error as below which I don't understand. Can anybody advise me a clue?
vendor.0d0ecd6888946d189b3c.bundle.js:1 Uncaught Error: Cannot enable prod mode after platform setup. at ce (vendor.0d0ecd6888946d189b3c.bundle.js:1) at Object.cDNt (main.fbcb239d91994470baee.bundle.js:1) at n (inline.b01b7c89379b6ac4ad40.bundle.js:1) at Object.0 (main.fbcb239d91994470baee.bundle.js:1) at n (inline.b01b7c89379b6ac4ad40.bundle.js:1) at window.webpackJsonp (inline.b01b7c89379b6ac4ad40.bundle.js:1) at main.fbcb239d91994470baee.bundle.js:1 ce @ vendor.0d0ecd6888946d189b3c.bundle.js:1 cDNt @ main.fbcb239d91994470baee.bundle.js:1 n @ inline.b01b7c89379b6ac4ad40.bundle.js:1 0 @ main.fbcb239d91994470baee.bundle.js:1 n @ inline.b01b7c89379b6ac4ad40.bundle.js:1 window.webpackJsonp @ inline.b01b7c89379b6ac4ad40.bundle.js:1 (anonymous) @ main.fbcb239d91994470baee.bundle.js:1
BTW, the link url is like <a class="postlink" href="http://sub.mydomain.com/account/reset-password?userId=6&resetCode=1594AB7C31&tenantId=1">http://sub.mydomain.com/account/reset-p ... tenantId=1</a>
I just realized that not only the above url responses a blank screen, but also the login page is blank. I now can't login the application at all. It works days ago, and nothing changed on the server. All other .NET Core web sites on the same IIS are working fine. It looks like the IIS suddenly no longer to support Angular 2.
I tried to reboot IIS and the server, but no help. Does anybody have same experience?