Skip to content
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

DataLoader for CodeFirst Context loading #99

Closed
liben-y opened this issue Mar 1, 2018 · 6 comments
Closed

DataLoader for CodeFirst Context loading #99

liben-y opened this issue Mar 1, 2018 · 6 comments
Assignees

Comments

@liben-y
Copy link

liben-y commented Mar 1, 2018

This might already be possible but I couldn't find a way to getting it to work.

var dataLoader = new EntityDataLoader("name=SqlClientConnection");
DbConnection dbConnection = DbConnectionFactory.CreateTransient(dataLoader);
var myContext = new MyContext(_dbConnection);

Configuration for database connection:
<add name="SqlClientConnection" connectionString="Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />

When loading this is throwing errors.
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."

If the connection string is based on the System.Data.SqlClient provider this will not work as it is expecting EntityClient provider connection, but the EntityClient provider connection is used more for the database first connections and is not applicable for Code First. When trying to create a connection using the EntityClient provider but without the model files, again there are errors on loading as it expects the metadata property to have a value.

So this is a first question is it possible to get the loader working for CodeFirst? And if so how?

If not then I guess this should be documented its not possible and maybe a new feature request.

@JonathanMagnan JonathanMagnan self-assigned this Mar 3, 2018
@JonathanMagnan
Copy link
Member

Hello @Libeny ,

Do you think you could provide us a test project with this issue?

It will make easier/faster for my developer to getting started for investigating it.

We now always ask for a project since we found out that most issues are missing some essential information or are resolved by the requestor when creating it

Best Regards,

Jonathan

@liben-y
Copy link
Author

liben-y commented Mar 5, 2018

Hi Jonathan,

Thanks for looking into it.

I've attached the test project.
LoadRecordsFromSqlClientConnection.zip

Hopefully my intent is clear, let me know if you have any questions.

Regards

Liben

@JonathanMagnan
Copy link
Member

Thank a lot,

It will be assigned to one of my developers this week.

Best Regards,

Jonathan

@JonathanMagnan
Copy link
Member

Hello @Libeny ,

The DataLoader support for code first has been added in v1.3.3

You will need however to specify a context factory (that's used under the hood to make this feature work).

For example

EntityFrmeworkEffortManager.ContextFactory = (currentContext) => new EntitiesContext()

Best Regards,

Jonathan

@liben-y
Copy link
Author

liben-y commented Mar 14, 2018

Hi Jonathan,

I've just tested and its working, thanks a lot.

For anyone else trying to load using Code First the below snippet should help:

EntityFrameworkEffortManager.ContextFactory = context => new MyContext();

var dataLoader = new EntityDataLoader();
DbConnection dbConnection = DbConnectionFactory.CreateTransient(dataLoader);
var effortContext = new MyContext(dbConnection);

Regards

Liben

@liben-y liben-y closed this as completed Mar 14, 2018
@dis081278
Copy link

Where do you pass the connection string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants