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

Seeding EFFORT via Sql script file #89

Open
pearat opened this issue Nov 17, 2017 · 1 comment
Open

Seeding EFFORT via Sql script file #89

pearat opened this issue Nov 17, 2017 · 1 comment

Comments

@pearat
Copy link

pearat commented Nov 17, 2017

In attempting to seed the EFFORT database, it would be nice to use C#'s SqlClient namespace. However, after creating an Effort.Provider.EffortConnection, the casting of this to System.Data.SqlClient.SqlConnection fails so it's not possible to make subsequent calls to SqlCommand or ExecuteNonQuery(). See code sample below.

Any ideas on how to get this cast to work?

public static void Load_Data_Into_Effort(Effort.Provider.EffortConnection effortConnection) { string sql = seedData(); // returns sql script file contents System.Data.SqlClient.SqlConnection cnn = (SqlConnection)effortConnection; try { //cnn.Open(); // not sure if this call is necessary, since Effort Db is already open SqlCommand cmd = new SqlCommand(sql, cnn); cmd.ExecuteNonQuery(); cmd.Dispose(); cnn.Close(); } catch (Exception ex) { Debug.WriteLine($"Error: {ex}"); } }

@pearat pearat closed this as completed Nov 17, 2017
@pearat pearat reopened this Nov 17, 2017
@pearat
Copy link
Author

pearat commented Nov 17, 2017

I reviewed the discussion in issue #54 where you remark, " It only supports the database independent entity SQL statements," and provides a link to Microsoft's "Entity SQL" blog. From there I tried to get this code to work, but it also fails with a casting exception, since apparently the call to ObjectContext is a Core feature and EntityConnection requires its metadata to be .NET.
This may not solve it, but is there a way to convert MetadataWorkspace from Core back to .NET?

var metadata = ((IObjectContextAdapter)effortContext).ObjectContext.MetadataWorkspace; var _connection = new EntityConnection(metadata, effortConnection);

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

1 participant