-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warehousing - copy data from one database to another #399
Comments
You can do it injecting a keyed EF Core context in the dependency injection. Every EF Core operator supports an extra parameter to transmit the key of the connection/db context. |
provide you source cade that has an issue for me to help you at best |
Here's my test project. Program.cs
WarehouseContext.cs
SimpleTable.cs
|
like I mentionned in my first answer, you must inject your DbContexts by keying them: var processRunner = StreamProcessRunner.Create<string[]>(TestImport2.Import);
var executionOptions = new ExecutionOptions<string[]>
{
Resolver = new SimpleDependencyResolver()
.Register(new DataAccess.TestDbContext1(), "CNX1")
.Register(new DataAccess.TestDbContext2(), "CNX2")
};
var res = await processRunner.ExecuteAsync(args, executionOptions); then, in your stream, you must refer to the right keyed one using .EfCoreSave("Save composition", o => o
.WithKeyedConnection("CNX1")
.Entity(i => i.Composition)
.SeekOn(i => new { i.Date, i.PortfolioId })
.DoNotUpdateIfExists()
.Output((i, e) => new
{
i.Portfolio,
Composition = e
})); |
If you cannot have your code sample working with my precisions, I will find time to rehandle your code working asap. |
Based on your answer I've managed to make the "read from Native SQL db1 and write to Native SQL db2" solution work. But I'm still unable to do it with Entity Framework.
But none of these two worked for me. Could you please help and give me a working example? Easiest to understand would be if you reworked my very minimalistic solution from 12/20/2022. For reference, here's the working "read from Native SQL db1 and write to Native SQL db2" solution:
(Sorry for replying so late, I was unavailable due to the holidays.) |
For entity framework read/write to work, you must inject the related DbContext(s) |
Yes, I did that already, I've injected the related DbContexts. Here's my code for reference:
Program.cs goes
I'd like to read from a source db using EF Core and write to a target db using EF Core. |
I see, I still to refactor a little bit efcore extensions for a better consistency with other extensions. |
I'm sorry, there was a mistake from my part and the solution in my previous comment (EFCore to EFCore) does work. The issue was that I forgot to properly attach the target database to the EF Core. Running "Add-Migration" and "Update-Database" on the target context (target database) solved the issue. I think this Github Issue can be closed as "injecting the dbcontexts" were the correct answer. If anything, an updated documentation on the library (https://paillave.github.io/Etl.Net/docs/intro) would be much appreciated. I couldn't find anything there which tells me how a source and target database connection comes into play. The closest I've found is the args[0] and args[1] parameters, but I'm still yet to figure out what args[0] does. |
The first parameter of the payload is the single value that is issued by the trigger stream. See the documentation for this: https://paillave.github.io/Etl.Net/docs/recipes/useExternalData#from-trigger-stream Like most of question issue, I'll leave this issue opened so that I can track what documentatio I still need to do. |
Hello, I tried to move data between two database but it didn't work, I checked the SQL server profiler and found out it reads the data, creates temp table and make insertion from that temp but no data inserted, Note, the ID on the insertion table is Auto generated. dose that effect? contextStream.EfCoreSelect("Get Transaction Data"
, (o, row) => o.Set<Transaction>()
.Select(t => new TransactionHeader
{
AccountId = t.AccountId,
AuthCode = t.AuthCode,
CreatedBy = t.CreatedBy,
TransactionId = t.Id,
CreationDate = t.CreationDate,
})
, connectionKey: "stg")
.EfCoreSave("Save transaction Data",
t => t.WithKeyedConnection("dwh")
.Entity(t => new TransactionHeader
{
AccountId = t.AccountId,
AuthCode = t.AuthCode,
CreatedBy = t.CreatedBy,
TransactionId = t.Id,
CreationDate = t.CreationDate,
})
.SeekOn(i => new { i.AuthCode, i.CreationDate })
); |
Did you ensure that the process worked properly by checking the property
Did you check how many rows are issued for each operators?
There is no problem with autogenerated ID, your code should work properly asis. Let me know. |
The issue was due forirgn key constrain, I think I need to log ExceuteAsync Results in the future. |
for a start you must ensure that the property |
Hi, can you read data from a source db and copy it to another, target db? I've read and tried the examples in the documentation, but read and save always happen inside the same database even though the documentation mentions 2 args parameters.
Please provide example code if it's possible.
The text was updated successfully, but these errors were encountered: