# Wednesday, April 21, 2010

When talking about the Model View ViewModel (MVVM) , Model View Controller (MVC) or any other presentation patterns Model some people refer to it as the Database Model, others as the Domain Model. Well, it is actually referred as a Presentation Data Model.

Your database or domain types could have many properties that the View does not care about and it will be a waste of resources as well as a security risk to have all that data traveling back and fourth the network even if it is an intranet.

Another problem with using Database or Domain data in your MVVM is that any change to the database or domain will require to update all the clients and that could be very costly.

Let's assume for example that we have the following very simple Domain Model:

SSLDomain

and the following Database Model:

image

Note: I created the Database Model using the following NHibernate mapping:

     
 
<?xml version="1.0" encoding="utf-8"?>
<!--Generated with CyberBizSoft's NHibernate Helper on 12/16/2009 11:30:06 PM -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CyberBizSoft.SSL.Domain" 
namespace="CBSI.SSL.Domain">
    <class name="Store" table="SSLStores" lazy="false" >
        <id name="ID" unsaved-value="0" column="ID" type="System.Int64">
            <generator class="identity" />
        </id>
        <property name="Name"/>
        <property name="Description"/>
        <component name="Contact" class="CBSI.Common.Domain.SingleContact, 
CyberBizSoft.Domain" >
            <component name="Address" class="CBSI.Common.Domain.Address, CyberBizSoft.Domain">
                <property name="Street" column="Street" />
                <property name="City" column="City" />
                <property name="State" column="State" />
                <property name="ZipCodeNumber" column="ZipCodeNumber" />
                <property name="Country" column="Country" />
            </component>
            <component name="Phone" class="CBSI.Common.Domain.Phone, CyberBizSoft.Domain">
                <property name="FullNumber" column="PhoneNumber"/>
            </component>
            <component name="Fax" class="CBSI.Common.Domain.Phone, CyberBizSoft.Domain">
                <property name="FullNumber" column="FaxNumber"/>
            </component>
            <component name="EMail" class="CBSI.Common.Domain.Url, CyberBizSoft.Domain">
                <property name="URL" column="EMailAddress"/>
            </component>
            <component name="Web" class="CBSI.Common.Domain.Url, CyberBizSoft.Domain">
                <property name="URL" column="WebAddress"/>
            </component>
        </component>
    </class>
    <!--Copyright (c) 2001 - 2009 by CyberBizSoft, Inc. All rights reserved.-->
</hibernate-mapping
 
     

 

Let's say that we have to create an interface only to change the Name and Description of this Store. Why would we have to bring all the other information into the client if we only need the Store's ID, Name & maybe Description?

Preferably we could create a very simple presentation data model (StoreNameModel) which we could adorn with presentation specific attributes,

class StoreNameModel
{
    [Key]
    public long ID { get; set; }
    [Required]
    public string Name { get; set; }
    public string Description { get; set; }
}

map the data from the Domain Store in the service to the StoreNameModel

public IQueryable<StoreNameModel> Stores()
{
    return from c in Repository.All
           orderby (c.Name)
           select new StoreNameModel() { ID = c.ID, Name = c.Name, Description = c.Description };
}

and then project it into the ViewModel in the client.

Update (4/23/10)

I found this post by Deepesh Mohnani about the WCF RIA Presentation Model    

 

 
posted on Wednesday, April 21, 2010 6:43:46 PM UTC  #    Comments [0]
# Tuesday, April 20, 2010

If you create a Silverlight application using the WCF RIA Services Class library and with the following walkthrough when you try to access the Context for the RIA application (WebContext) it is not there.

Since we did not enabled the WCF RIA Services for the Silverlight application the WebContext class is not generated in the client.

  image

You can verify this by selecting the Silverlight application in the Solution Explorer, click the Show All Files button in the Solution Explorer toolbar and then inspecting the hidden "Generated_Code" folder.

The workaround is to right click on the Silverlight application in the Solution Explorer, select Properties and  temporarily enable the WCF RIA Services by selecting the web project in the WCF RIA Service link.

 image

Then rebuild the solution find and copy the WebContext class in the file [YourServerAssemblyName].g.cs in the afore mentioned folder to a new file WebContext.cs somewhere in the Silverlight application project.

Now right click on the Silverlight application in the Solution Explorer again and select <No Project Set> in the WCF RIA Service link and rebuild again. "Generated_Code" folder content will be removed.

This is kind of a hack and I believe it could be solved if the WCF RIA Services Class Library template will check if the WebContext exists in the Silverlight application and if not exist it will generate it.

Update (4/26/2010)

If you move the WebContext.cs file to the WCF RIA Services library client make sure to update your app.xaml with the following:

<app:WebContext>
            <app:WebContext.Authentication>
                <appsvc:FormsAuthentication
DomainContextType="[TheNamespaceOfYourRIALibrary].AuthenticationContext,
[TheNameOfYourRIAClassAssembly ], Version= [X].0.0.0"/>
                <!--<appsvc:WindowsAuthentication/>-->
            </app:WebContext.Authentication
   </app:WebContext
posted on Tuesday, April 20, 2010 6:56:54 PM UTC  #    Comments [0]
# Sunday, April 18, 2010

Digging through my old backups I found the following application that was one of the first I built using Visual Studio for a private investigation firm way back in 1997:

clip_image001[8]

 

It has been a long love-hate relationship with Visual Studio. Happy Birthday Visual Studio!

posted on Sunday, April 18, 2010 5:41:08 PM UTC  #    Comments [0]
# Saturday, April 17, 2010

I completed the upgrade to VS 2010 but with some warnings. Apparently nothing important.

image

[04/16/10,16:44:37] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'WinDiff.lnk' could not be set.

[04/16/10,16:44:37] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'OLE-COM Object Viewer.lnk' could not be set.

[04/16/10,16:44:38] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'Manifest Generation and Editing Tool.lnk' could not be set.

[04/16/10,16:44:38] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'Install Microsoft FXCop.lnk' could not be set.

***EndOfSession***

 

Here is my list: (I removed Visual Studio 2005 but not 2008)

image

UPDATE

Later today (4/17/2010) I noticed the following entries in the Application Event Log:

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetEntityDataModelVB_ASPNET.zip), file (ModelObjectItemVB_ASPNET.vstemplate). Invalid template element (TemplateID) value (Microsoft.Data.Entity.Design.VSTemplate.ModelObjectItemVB_ASPNET).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetEntityDataModelCSharp_ASPNET.zip), file (ModelObjectItemCS_ASPNET.vstemplate). Invalid template element (TemplateID) value (Microsoft.Data.Entity.Design.VSTemplate.ModelObjectItemCS_ASPNET).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetDataServiceVBWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetDataServiceVBWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetDataServiceCSharpWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetDataServiceCSharpWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\1033\AdoNetDataServiceVBWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\1033\AdoNetDataServiceVBWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\AdoNetDataServiceCSharpWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\AdoNetDataServiceCSharpWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

 

Although all these Item Templates where present, I ran "DevEnv.exe /installvstemplates" from an Administrator Visual Studio Command Prompt (2010) just in case.

posted on Saturday, April 17, 2010 4:23:50 AM UTC  #    Comments [0]