This project is read-only.

Using EFDAL without a connection string in app.config?

Oct 13, 2010 at 11:21 PM

Is it possible to use the whole of nHydrate's EFDAL without a connection string in app.config? That is, one that is created at runtime.

I have found DBHelper used by AuditPaging, DeleteData and BusinessObjectQuery and I don't think I can replace or override DBHelper based on the way you generate the internal class.

Any suggestions?




Oct 14, 2010 at 6:18 PM

I am looking into this. Will provide an update before monday

Oct 14, 2010 at 10:05 PM
Edited Oct 14, 2010 at 11:23 PM

Thanks for doing that.

My work round is to change first few lines in CustomerEntities.Generated.cs, where Customer is my Entity, and in the associated partial class I have MyConString() obtaining the runtime connection string and I have a blank entry in app.config. So, my workround needs the generated code to be changed.

                           internal static string GetConnectionString()

string s = System.Configuration.ConfigurationManager.ConnectionStrings["CustomerEntities"].ConnectionString;
                        if (String.IsNullOrEmpty(s))
                          s = CustomerEntities.MyConString();

However, in doing this two things have occured to me.

 (a) You don't need to do that Regex stuff to get the SQL Connection String. Its available from something like this
EntityConnection ec = new EntityConnection(//the ef conn string);
sc = ec.StoreConnection;
string scs = sc.ConnectionString;

(b) Why are you going to SQL to get the Audit records, and not staying with EF4?


Oct 15, 2010 at 12:55 AM

Here's my temporary solution:-


#region Connection String
sb.AppendLine(" internal static string GetConnectionString()");
sb.AppendLine(" {");
sb.AppendLine(" string s = System.Configuration.ConfigurationManager.ConnectionStrings[\"" + _model.ProjectName + "Entities\"].ConnectionString;");
sb.AppendLine("         if (String.IsNullOrEmpty(s))");
sb.AppendLine("           s = " + _model.ProjectName + "Entities.MyConString();");
sb.AppendLine("         EntityConnection ec = new EntityConnection(s);");
sb.AppendLine("         SqlConnection sc = ec.StoreConnection as SqlConnection;");
sb.AppendLine("         string scs = sc.ConnectionString;");
sb.AppendLine(" return scs;");
sb.AppendLine(" }");

Where I'm putting MyConString() in the associated partial class, and of course adding the references to
Bit labourious changing the code generator - wish it was a T4 template!!
So now I can get 

var ac = cust1.GetAuditRecords();

to work.

I'm sure you can find a better solution. A ConnectionString Provider would be nice.


Oct 15, 2010 at 11:03 PM

I've simplfied my solution and modified the EFDAL generator, and I've  put the source of my updated EFDAL on my blog,

Hope someone finds it useful