May 2010 Entries
The opinions mentioned herein are solely mine and do not reflect those of my employer
Wanted to post this for a long time but couldn’t. I have been an ASP.NET Developer for quite sometime and have worked with version 1.1, 2.0, 3.5 as well as the latest 4.0.
With ASP.NET 2.0 and Visual Studio 2005, came the era of AJAX and rich UI style web applications. So, ASP.NET AJAX (codenamed “ATLAS”) was released almost an year later. This was called as ASP.NET 2.0 AJAX Extensions. This release was supported further with Visual Studio 2005 Service Pack 1.
The initial release of ASP.NET AJAX had 3 components
ASP.NET AJAX Library – Client library that is used internally by the server controls as well as scripts that can be used to write hand coded ajax style pages
ASP.NET AJAX Extensions – Server controls i.e. ScriptManager,Proxy, UpdatePanel, UpdateProgress and Timer server controls. Works pretty much like other server controls in terms of development and render client side behavior automatically
AJAX Control Toolkit – Set of server controls that extend a behavior or a capability. Ex.- AutoCompleteExtender
The AJAX Control Toolkit was a separate download from CodePlex while the first two get installed when you install ASP.NET AJAX Extensions.
With Visual Studio 2008, ASP.NET AJAX made its way into the runtime. So one doesn’t need to separately install the AJAX Extensions. However, the AJAX Control Toolkit still remained as a community project that can be downloaded from CodePlex. By then, the toolkit had close to 30 controls.
So, the approach was clear viz., client side programming using ASP.NET AJAX Library and server side model using built-in controls (UpdatePanel) and/or AJAX Control Toolkit.
However, with Visual Studio 2008 Service Pack 1, we also added support for the ever increasing popular jQuery library. That is, you can use jQuery along with ASP.NET and would also get intellisense for jQuery in Visual Studio 2008.
Some of you who have played with Visual Studio 2010 Beta and .NET Framework 4 Beta, would also have explored the new AJAX Library which had a lot of templates, live bindings etc.,
But, overall, the road map ahead makes it much simplified.
For server side programming one you can use the server controls like UpdatePanel etc., and also the AJAX Control Toolkit which has close to 40 controls now. The AJAX Control Toolkit still remains as a separate download at CodePlex. You can download the different versions for different versions of ASP.NET at http://ajaxcontroltoolkit.codeplex.com/
The Microsoft AJAX Library will still be available through the CDN (Content Delivery Network) channels. You can view the CDN resources at http://www.asp.net/ajaxlibrary/CDN.ashx The versions available in CDN include the 3.5 version as well as 4.0 version of the scripts. This is specifically to help if you already invested in development using ASP.NET AJAX 4.0 as well as for those who don’t want to use jQuery
Similarly even jQuery and the toolkit would be available as CDN resources in case you chose not to download and have them as a part of your application.
I think this makes AJAX development pretty simple. Earlier, having Microsoft AJAX Library as well as jQuery for client side scripting was kind of confusing on which one to use. With this roadmap, it makes it simple and clear.
You can read more on this at http://ajax.asp.net
I hope this post provided some clarity on the AJAX roadmap as I could decipher from various product teams.
When working with ADO.NET Entity Data Model, its often common that we generate entity schema for more than a single table from our Database. With Entity Model generation automated by Visual Studio, it becomes even more tempting to create and work with entity models to achieve an object mapping relationship.
One of the errors that you might hit while trying to update an entity set either programmatically using context.SaveChanges or while using the automatic insert/update code generated by GridView etc., is “Unable to update the EntitySet <ENTITY NAME> because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation”
While the description is pretty lengthy, the immediate thing that would come to our mind is to open our the entity model generated code and see if you can update it accordingly.
However, the first thing to check is that, if the Entity Set is generated from a table, whether the table has a primary key definition. Most of the times, we create tables with primary keys. But some reference tables and tables which don’t have a primary key cannot be updated using the context of Entity and hence it would throw this error. Unless it is a View, in which case, the default model is read-only, most of the times the above error occurs since there is no primary key defined in the table.
Once you add a primary key constraint to the table in the database design, there are couple of steps to do until you can resolve the issue
1. Open the EDMX file in the design mode
2. Right click on the design view and select "Modal Browser"
3. The Modal Browser window opens on the right hand side
4. Select the <ModelName>.Store and right click
5. Select "Update Model from Database"
6. It will give you different options to add Tables, Delete Tables and a Refresh tab which mentions a list of database types that would be refreshed
7. If you are just getting the updated model after adding the primary key constraint as in our example, you can directly click "Finish"
8. At this point, we would expect everything should work fine since the primary key constraint is added and the build should be fine to go through
9. But if you build the solution/project you would receive a "3002 Error" describing that the storage models and conceptual models are not compatible.
10. You need to manually open the Model1.edmx again. Right click on the Model1.edmx and select "Open with"
11. Then select "XML (Text) Editor"
12. It will ask you confirmation to close the existing open model. Confirm by pressing "Yes"
13. This would present you an XML view of the model (I dont know a better way of directly coming to this view, if any post, in comments)
14. Find the section <edmx:ConceptualModels>
15. Under that go the EntityTypes section with the name of the table which you updated with primary key
16. You will find that under the <Key> collection, additional columns defined as PropertyRef
17. You need to the remove the additional columns and just have the Primray key column within the <Key> section
18. This is updated in the StorageModel section automatically but not in the conceptualmodel as of today.
19. Once you make this change and save, you should be able to build the project successfuly and also be able to update it programmatically by code
20. As I write this, I am also raising it in Microsoft Connect as to why the "update model" doesn't do a clean job of updating the schema. Would post clarifications any, if I receive.
There are other reasons why this error could popup which I am not going into for the sake of simplicity of the post. If you find something new, please feel free to share it in comments.
Hope this helps.
Recently I surfaced a problem where, one of my friend had a tough time in getting rid of an assembly reference error. Despite adding reference to the assembly, while referencing it in code, it was spitting out the “The type or namespace name ‘ASSEMBLYNAME’ could not be found” error. This was a migration project and owing to the above error, it was throwing another 100 errors.
We tried adding reference to the assembly in other projects and it was not even resolving the namespace while typing out in the using section.
Upon further digging into the error warnings, it indicated something to do with the .NET Framework targeted i.e. 4.0. My suspicion grew since the target framework was 4.0 and the assembly should be able to be recognized.
Then, when we checked “Project – “<APPNAME> Properties…”, the issue was with the default target framework which is “.NET Framework 4 Client Profile”
By default, Visual Studio 2010 creates Windows Forms App/WPF Apps with the Target Framework set to .NET Framework 4 Client Profile. This is to minimize the framework size required to be bundled along with the app. Client Profile is new feature since .NET 3.5 SP1 that allows users to package a minified version of .NET Framework that doesn’t include stuff such as ASP.NET, Server programming assemblies and few other assemblies which are typically never used in the Desktop Applications.
Since the .NET Framework client profile is a minified version, it doesn’t contain all the assemblies related to Web services and other deprecated assemblies. However, this application is a migration app and needed some of the references from Services and hence couldn’t run.
Once, we changed the Target Framework to .NET Framework 4 instead of the default client profile, the application compiled.
Here is link to a very nice article that explains the features of .NET Framework 4 client Profile, the assemblies supported by default etc., http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx