This project is read-only.
1
Vote

Unable to delete when using ContextStartup

description

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))

to

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,
Alex

comments

alprinias wrote May 27, 2014 at 5:15 PM

Update:

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();
            try
            {
                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 { }
            this.OnContextCreated();
        }
Alex