Multiple Shapes in ASP.NET MVC – Part 2

In my last article I discussed multiple shapes in ASP.NET MVC, in this article I’ll discuss to get around some of the problems that I’ve faced.

Problem 1: There’s no constructor – solved!

'System.Data.Linq.DataContext' not contain a constructor that takes '0' arguments

The first issue was to do with the error shown above which was received upon trying to build the project.

Today I returned to my development environment with a clean conscience and a load of caffeine.  Quite often you’ll find that ignoring the issue altogether and coming back to it helps, as well as spending the weekend reading some C. S. Lewis novel.  Again I tried to build the project where I was yet again greeted with the same frustrating message.  I had discussed the issue on Stack Overflow but the answers I was receiving didn’t fully tie in with the issue at hand.  I considered the partial class to inherit the same class as any other share partial class, which is indeed true, but there were some factors that I hadn’t previously noticed.  If, when you create a dbml file, you right-click and hit “View Code” it will create a partial class for the name of the dbml file which is expected.  The only issue with this newly created partial class (for placing custom code where you may return multiple shapes from stored procedures which LINQ can’t do for you) is that it places the partial class in the root namespace.  I’ve reproduced this problem with other dbml files so I think it’s a bug.  If someone could confirm I would be most grateful.  So, the solution?  Append the rest of the namespace!  Make sure your <filename>.designer.cs for your dbml file has a namespace that matches that of the filename.cs partial class.  Do not modify the <filename>.designer.cs file, Visual Studio will delete it and you will lose everything.

Problem 2: Passing a type failed to build project – solved!

Inherits=”System.Web.Mvc.ViewPage<MyType>

The second issue was with the above statement telling the user upon compile that MyType doesn’t exist.

Unfortunately I’ve left the exact details on another system but I used this blog post to aid me in my quest.  You simply have to add certain sections into your web.config in order to get it to work.  The MVC project setup is quite strange.  For me there are two web.config files, one of them has the things that are missing in them, the other does not.  Perhaps I have my environment set up wrong.  Simply put, I copied the missing contents from one web.config into the other web.config and hey presto, everything worked fine.

Conclusion

These things take getting used to, especially when you’re not used to working with a web environment which is really quite different from any other you’ve worked with.  Problem 1 seemed to me to be a bug with Visual Studio, what’s the point in having a partial class that doesn’t belong to the same namespace? It won’t compile as the same class surely?  Problem 2 also seemed silly because without those settings multiple shapes won’t work in your project, these details should’ve been in the web.config beforehand.

Either way, it’s not well documented and it takes forever to solve the problem.  The good news is that I actually managed to get some data output to screen, despite not being very enthusiastic.

About Kieran

A twenty-four year old software developer from Guernsey, Channel Islands.
This entry was posted in Pages. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>