MVC or SQL problem? not sure? ?? MVC bug(s) ??

Last post 04-28-2009 12:31 AM by paul.vencill. 8 replies.

Sort Posts:

  • MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-21-2009, 9:42 AM
    • Contributor
      6,827 point Contributor
    • gerrylowry
    • Member since 07-02-2008, 9:46 PM
    • alliston ontario canada
    • Posts 2,304

    I'm creating a non-trivial but relatively simple ASP.NET MVC v1.0 applet ~~
    it's very much similar to the movie database example of tutorial number one.

    It was working, more or less, until I added the Edit code.  It dies in code like
                  [AcceptVerbs(HttpVerbs.Post)]
                  public ActionResult Edit(Movie movieToEdit) 
    on
                  _db.ApplyPropertyChanges(originalMovie.EntityKey.EntitySetName, movieToEdit);

    The reason it's dying is because it's unhappy with the SQL timestamp field I've added:
                  changeControl  timestamp

    The fix should be simple, although I'm momentarily unsure of the syntax:  I'm guessing I need to
    add something like [Bind(Exclude = "changeControl")]  to:
                  [AcceptVerbs(HttpVerbs.Post)]
                  public ActionResult Edit(Movie movieToEdit, [Bind(Exclude = "changeControl")]

    Please note:  it seems to me that since timestamp fields are immutable from the
                        developer's perspective (AFAIK, only SQL Server can change them),
                        this looks like a MVC bug to me.    ?? bug # 1 ??

    MORE  INFORMATION (problem description)

    Here's the problem that I'm having:
    I noticed that I had spelled "changeControl" incorrectly as "chnageControl".

    In the .mdf, via the Server Explorer, I correct "chnageControl" to "changeControl".

    Problem:  every time I try to run my MVC solution, it dies at

            public ActionResult Index()  // Article Controller "Index"
            {
                return View(_db.NewsArticleSet.ToList());     // dies here
            }                

    with         {"Invalid column name 'chnageControl'."}

    I have used VS2008 Pro SP1 Find to hunt for chnageControl throughout my entire
    solution and it can not find it.  I've examined the .mdf in Server Explorer
    and see no trace of 
    chnageControl.  I even copied the .mdf to another computer and
    attached it to SQL Server 2008 Express to examine it in a different environment.
    Again, I can find no trace of
    chnageControl.  I've even rebooted my development computer,
    again, without success.

    How do I make VS2008 forget about the 
    chnageControl artifact?   ?? bug # 2 ??

    Thank you.
     

    Regards,
    Gerry (Lowry)

    System.Data.EntityCommandExecutionException was unhandled by user code
      Message="An error occurred while executing the command definition. See the inner exception for details."
      Source="System.Data.Entity"
      StackTrace:
           at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behaviour)
           at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
           at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
           at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
           at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
           at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
           at mne.Controllers.ArticleController.Index() in C:\!!!!!mne\mne\mne\Controllers\ArticleController.cs:line 34
           at lambda_method(ExecutionScope , ControllerBase , Object[] )
           at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
           at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
           at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
           at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
      InnerException: System.Data.SqlClient.SqlException
           Message="Invalid column name 'chnageControl'."       ?? bug # 2 ??
           Source=".Net SqlClient Data Provider"
           ErrorCode=-2146232060
           Class=16
           LineNumber=21
           Number=207
           Procedure=""
           Server="\\\\.\\pipe\\49364F80-F3FA-40\\tsql\\query"
           State=1
           StackTrace:
                at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
                at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
                at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
                at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
                at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
                at System.Data.SqlClient.SqlDataReader.get_MetaData()
                at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
                at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
                at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
                at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
                at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
                at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
                at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
                at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
           InnerException:

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · gerry.lowry@abilitybusinesscomputerservices.com

    Websites:
    http://abilitybusinesscomputerservices.com
    http://gerrylowryprogrammer.com ~~ résumé & testimonials
    http://veganoccasions.com ~~ recipes by Susan
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-21-2009, 12:56 PM
    Answer
    • Member
      105 point Member
    • punkracy
    • Member since 02-05-2009, 4:39 PM
    • POZnan* | Poland
    • Posts 29

     Are you using Linq2Sql or EF?

    For example, when I use Linq and I add new table and after adding all columns I grab this table and put it in the .dbml file. Safe the file and it generate the appropriate code. When I made some changes in the table I need to open .dbml file remove the table from diagram and drag'n'drop it once again (new code will be generated). Of course you lose all associations and you need to do the again.

    Similar situation in EF.

     

    Best regards

    Don't forget to click "Mark as Answer" on the post that helped you.
    http://punkracy.com
    http://tembo.pl
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-21-2009, 2:09 PM
    Answer
    • Contributor
      6,620 point Contributor
    • paul.vencill
    • Member since 02-01-2006, 7:57 AM
    • Gaithersburg, MD
    • Posts 1,350

     As punk said, this is an ORM problem not an MVC one; both EF and Linq to SQL have the same problem.  If you whack that class on the design surface and then re-add it, then assuming your tables have the right column name in the db now, you should be good to go.  Also, you should be able to change the behavior you're asking about in the ORM designer as well, by clicking on that property and modifying its change tracking field in the property explorer.  I think the value to change it to is "Never" in Linq to SQL, can't recall if it's the same in EF or not. 

    Hope that helps

    Paul

    Help those who have helped you... remember to "Mark as Answered"
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-21-2009, 11:56 PM
    Answer
    • Member
      402 point Member
    • Sohan
    • Member since 11-18-2008, 9:00 AM
    • Dhaka
    • Posts 66

    You need to update your dbml file to match the database column name with what you have the dbml file. Please note that dbml is only a design time thing and is not supposed to auto update and sync when you change in your database, unless you manually do it. For now, you need to either edit the designer.cs file manually or re-drag the item in the design surface.

    --
    (Please, Mark as Answer if it Helped)
    http://smsohan.blogspot.com
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-25-2009, 9:36 AM
    Answer
    • Contributor
      6,827 point Contributor
    • gerrylowry
    • Member since 07-02-2008, 9:46 PM
    • alliston ontario canada
    • Posts 2,304

     http://www.scip.be/index.php?Page=ArticlesNET12&Lang=NL
    .NET - ADO.NET Entity Framework & LINQ to Entities - deel 1

    @ punkracy:  Entity Framework (hence .edmx instead of .dbml)

    @ paul.vencill:  yes, the problem is refactoring is not integrated enough;
                           it's okay if the ORM does not get refactored although
                           it would be better for productivity if it did, preferably
                           interactively.  Forgive me when I suggest that x isA Bug
                           when in fact y isThe Bug; this is a side effect caused
                           because I'm currently drowning in Lake APS.NET MVC v1.0.

    @ sohan:  yes, the problem is no matter how much I searched
                    I could not find the source of the artifact memory of "chnageControl".

      --------------------------------------------------------------------------------------

    This creates a huge productivity hit on the developer.
    I've spent far too much time digging for answers.  I did find
    some interesting articles, examples:
    http://www.thinqlinq.com/default/Changing-the-Namespace-on-generated-Entity-Framework-classes.aspx

    http://www.scip.be/index.php?Page=ArticlesNET12&Lang=NL
    .NET - ADO.NET Entity Framework & LINQ to Entities - deel 1

    http://scruffylookingcatherder.com/archive/2008/08/27/changing-table-names-in-an-orm.aspx

    more at:
    http://www.google.com/search?hl=en&safe=off&rls=com.microsoft%3A*&num=100&newwindow=1&q=dbml+edmx+-huagati&btnG=Search

    The evil problem is that although Visual Studio attempts to ease the pain of refactoring,
    a small change like changing a field name in a .mdf table ends up causing lots of grief.

    When I deleted my .edmx, first I was not allowed to recreate with the same name
    because the wizard objected.  Then I had to change my source to match the changes
    that the wizard caused me to make.

    I think the solution to the above problem is to delete the .edmx, create a new one
    with a different name, delete the old one; it may still be necessary to alter one's
    source for a clean compile; I can not remember all the painful steps because
    this process was so frustrating.  Next time, I'll use this trick:  wherever
    a change is forced as a side effect, preface it with something unique, e.g.: edmxKludge.
    Next, delete the new .edmx and restore the previous one (with its corrected column(s) this time),
    then globally search and replace edmxKludge with nothing.

    As I've already stated, this creates a huge productivity hit on the developer.

    What bothers me the most is that no matter what I did, I could not hunt down
    the source of the artifact memory of "chnageControl".

    Thank you all for your help.

    Regards,
    Gerry (Lowry)

    P.S.:  this is not fully sorted out, more to come, either here or in a separate post.

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · gerry.lowry@abilitybusinesscomputerservices.com

    Websites:
    http://abilitybusinesscomputerservices.com
    http://gerrylowryprogrammer.com ~~ résumé & testimonials
    http://veganoccasions.com ~~ recipes by Susan
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-25-2009, 11:55 AM
    • Contributor
      6,827 point Contributor
    • gerrylowry
    • Member since 07-02-2008, 9:46 PM
    • alliston ontario canada
    • Posts 2,304

    continued here:  http://forums.asp.net/p/1415502/3118429.aspx#3118429
                            "timestamp woes ~~ [Bind(Exclude = "changeControl")] et cetera fails".
    /g/

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · gerry.lowry@abilitybusinesscomputerservices.com

    Websites:
    http://abilitybusinesscomputerservices.com
    http://gerrylowryprogrammer.com ~~ résumé & testimonials
    http://veganoccasions.com ~~ recipes by Susan
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-25-2009, 10:38 PM
    • Contributor
      6,620 point Contributor
    • paul.vencill
    • Member since 02-01-2006, 7:57 AM
    • Gaithersburg, MD
    • Posts 1,350

    @Gerry,

    You'll get no argument from me; I have purposely stayed away from EF for production apps for just the types of reasons you cite.  I tried it on a few tests and it's just way too clunky in a number of ways.

    I am now in the habit of developing my apps completel w/o permanent persistence solution in mind, then I do the persistence after the model's nice and stable.  I end up not often using things like the Linq to Sql Designer or EF Designer as a result, but I find myself having a much easier time refactoring and overall I wind  up more productive.  Even using oen of hte ORM solutions inside the repository layer is a lot easier once you have the model stable on the object side, and I'm *really* hoping that MS lives up to their promise of enabling model-first design next go-round.  I haven't seen many other ORMs do that well at all (Ruby on Rails being the most noteworthy exception), but I'd sure benefit if it's clean enough.

    Help those who have helped you... remember to "Mark as Answered"
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-27-2009, 8:16 AM
    • Contributor
      6,827 point Contributor
    • gerrylowry
    • Member since 07-02-2008, 9:46 PM
    • alliston ontario canada
    • Posts 2,304

    @ Paul ... hi Paul ~~ just curious, did you get a chance to look at
      http://forums.asp.net/p/1415502/3118429.aspx#3118429 ?

    The timestamp field is killing me ... how do you deal with timestamp fields?
    Do you use them or avoid them?

    My (probably incorrect) understanding is that timestamp fields
    belong to SQL and can be referenced but should not (and
    probably can not) be tampered with by the developer ~~ i.e.,
    AFAIK, timestamp fields are more for SQL Server's house keeping
    as well as a way of knowing if someone else updated the
    server instead of you, as in pseudo code:
                  if (savedTimeStamp != serverTimeStamp)
                            abortUpdate;

    g.

    P.S.:  is it just my perception?  it seems that now more people
             are really using ASP.NET MVC v1.0 and running into all
             kinds of challenges that were either not covered in the
             tutorials, or were barely covered so that one has to do
             quite a bit of reading between the lines.  Short term,
             WebForms were a lot easier for me to get something
             done rather quickly.  ASP.NET MVC is taking me quite
             a bit longer.  In my case, I'm working on a very small
             fixed price contract and losing my shirt.

    Gerry Lowry, Principal
    Ability Business Computer Services ~~ Because it's your Business, our Experience Counts!
    68 John W. Taylor Avenue
    Alliston · Ontario · Canada · L9R 0E1 · gerry.lowry@abilitybusinesscomputerservices.com

    Websites:
    http://abilitybusinesscomputerservices.com
    http://gerrylowryprogrammer.com ~~ résumé & testimonials
    http://veganoccasions.com ~~ recipes by Susan
    Filed under:
  • Re: MVC or SQL problem? not sure? ?? MVC bug(s) ??

    04-28-2009, 12:31 AM
    • Contributor
      6,620 point Contributor
    • paul.vencill
    • Member since 02-01-2006, 7:57 AM
    • Gaithersburg, MD
    • Posts 1,350

    hm... haven't looked at it; looking now.  Will post.

     with regard to your contract, ah... but are you takign into account the value of the learning ? :D  j/k/  The thing to me is that WebForms are easier for beginners, but a *lot* harder the more experienced you get, to get them tweaked to work well with web standards and performance and so on. They intentionally mask the web environment, which makes it easier for folks coming from desktop apps, but if you want to make a solid n-tier app that plays well across browsers and plays well with CSS, you're in for a lot more work.

    Help those who have helped you... remember to "Mark as Answered"
Page 1 of 1 (9 items)