Unable to delete when using ContextStartup


Hi everybody,

this must be related to discussion item: https://nhydrate.codeplex.com/discussions/358123

I recently modified my main "SaveChanges" procedure form

using (var cont = new MyEntities(myConnectionString))


using(var cont = new MyEntities(new ContextStartup(myLogin), myConnectionString))

and I found out that I wasn't anymore able to delete. For some reason, when the ContextStartup is added, when I try to delete, the generated code is accessing a the GetConnectionString() method, which tries to get the connection string from the configuration file, and ignores my second parameter to the MyEntities constructor.

Is there a way to use the myConnectionString parameter and at the same time the contextStartup so that I can have the modifier recorded ?

If you can also change the property from "Modifer" to "Modifier"... There is an "i" missing :-)

Best regards,


alprinias wrote May 27, 2014 at 4:15 PM


Solved the problem by adding a context constructor with both the connectionString and the ContextStartup, based on the constructor with just the connectionString. Just added the line where I set the private property _contextStartup at the beginning of the method:
        public MyEntities(string connectionString, ContextStartup contextStartup) :
            base(Util.ConvertNormalCS2EF(connectionString), "MyEntities")
            _contextStartup = contextStartup;

            this.CurrentPlatform = Util.GetDefinedPlatform();
                var builder = new System.Data.Odbc.OdbcConnectionStringBuilder(Util.StripEFCS2Normal(this.Connection.ConnectionString));
                var timeoutValue = "30";
                if (builder.ContainsKey("connect timeout"))
                    timeoutValue = (string)builder["connect timeout"];
                else if (builder.ContainsKey("connection timeout"))
                    timeoutValue = (string)builder["connection timeout"];
                var v = Convert.ToInt32(timeoutValue);
                if (v > 0)
                    this.CommandTimeout = v;
            catch { }