August 2008
M T W T F S S
« Jul    
 123
45678910
11121314151617
18192021222324
25262728293031

Archive for the '.NET' Category

09
Jan

Updating a Entity Framework Beta 3 model after a DB change

The tools for Entity Framework are trailing way behind the Entiy Framework itself. I have been running into a lot of problems lately with changes I make to Table are not reflected in my Entity Model. It is a real pain to have to recreate the entire model every time. So here is what I figured out to fix it. I’ll give a step by step guide.

PreReqs:

You have an existing mode.

You have added a column to your Table.

 

Open the model viewer (GUI).

Right click on open space and select Model Browser. That will bring up the model browser on the right side.

In the MB select you model, right click and select ‘Update Model from Database’.

 

NOTE: The act of updating from SQL will make <!– SSDL content –>(model.ssdl) of your model correct and up to date. The <!– C-S mapping content –>(model.msl) and <!– CSDL content –>(model.csdl) are still broken.

 

To fix the other two, in “Solution Explorer” right click on you model (.edmx) and select “Open With”. Select “XML Edior”.

In the top section <!– CSDL content –> locate your table and add your column. For me it was WorkspaceNavigationType.

 

<EntityType Name=”WorkspaceNavigationType”>
          <Key>
            <PropertyRef Name=”NavigationTypeID” />
          </Key>
          <Property Name=”NavigationTypeID” Type=”Int32″ Nullable=”false” />
          <Property Name=”Title” Type=”String” Nullable=”false” MaxLength=”50″ Unicode=”false” />
          <Property Name=”PeterColumn” Type=”Int32″ Nullable=”false” />
          <Property Name=”Lous” Type=”Int32″ Nullable=”false” />
          <Property Name=”MyColumn” Type=”Int32″ Nullable=”false” />
          <Property Name=”Description” Type=”String” MaxLength=”50″ Unicode=”false” />
          <NavigationProperty Name=”WorkspaceNavigationTrees” Relationship=”HCMS.DataAccessLayer.Models.WorkspaceNavigation.FK_WorkspaceNavigationTrees_WorkspaceNavigationType” FromRole=”WorkspaceNavigationType” ToRole=”WorkspaceNavigationTrees” />
        </EntityType>

 

Go down to the bottom of the XML and located the <!– CSDL content –>  tag and located your table in there.

 

<EntitySetMapping Name=”WorkspaceNavigationType”>
            <EntityTypeMapping TypeName=”IsTypeOf(HCMS.DataAccessLayer.Models.WorkspaceNavigation.WorkspaceNavigationType)”>
              <MappingFragment StoreEntitySet=”WorkspaceNavigationType”>
                <ScalarProperty Name=”NavigationTypeID” ColumnName=”NavigationTypeID” />
                <ScalarProperty Name=”Title” ColumnName=”Title” />
                <ScalarProperty Name=”Description” ColumnName=”Description” />
                <ScalarProperty Name=”PeterColumn” ColumnName=”PeterColumn” />
                <ScalarProperty Name=”Lous” ColumnName=”Lous” />
                <ScalarProperty Name=”MyColumn” ColumnName=”MyColumn” />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>

 

Save the XML, and compile Your done. If you open your model browser, you will see your new column (or changed).

28
Dec

TFS Proxy server in non trusted remote domain

I ran into a problem that I am sure more people than me run into. I had to install TFS into a remote office of developers that are contracted. To make it worse the remote office is 5000 miles away. Now since the developers are not employed by us I have the choice:

1. Leave them in their own domain and figure out how to make the remote domain work with TFS.
or

2. Connect their AD to ours and deal with the trust issues.

I decided on #1. Now I am a network guy so setting up the VPN between the two offices was a piece of cake. I dropped a WatchGuard Edge onto the remote next work and connected it to our home office for a secure VPN.

Now for the fun part. The proxy server connects to the main TFS server using the Identity of the Application Pool for the TFS Proxy Server Web Site. Since the remote AD and the TFS AD are not in the same domain, they can not authenticate to each other. But there is a hack.

In this scenario we will use 3 devices, Proxy server (PServer), TFS server (TServer), and remote client (client). There are two domains HomeAD (TFS server domain) and RemoteAD (Proxy and client domain).

TServer is in HomeAD
PServer is in RemoteAD
client is in RemoteAD

The hack is to create a local user on TServer, we will use proxyUser with a password or proxy123. Make that user a local admin and add that user to TFS.

In visual studio, in Team Explorer, right click on the TFS server (TServer), Team Foundation Server Settings, Group Membership. Click on Team Foundation Administrators then the properties button. Select the ‘Window User or Group’ radio button then Add. Add proxyUser and select OK. The user proxyUser is now an Administrator for the TFS server.

Now on the remote domain, RemoteAD, add the user proxyUser with the same password, proxy123.

On the TFS Proxy server open IIS. Locate the App Pool Team Foundation Server and open it. On the identity tab set the logon user to RemoteAD/proxyUser with proxy123 as the password. Run iisreset to reset the web site. Goto http://localhost:8081/VersionControl/v1.0/ProxyStatistics.asmx. Click Invoke. If you get XML that lists number of file fetched, files missed, etc.. then the link to the main TFS is up.

The client is simple. The client’s machine and username are in the RemoteAD domain. When the user connects to the TFS Proxy server (PServer), it will use the users login for the RemoteAD. When the user connects to the real TFS server (TServer) for check-ins and to get the security token, they will use their AD account that has been set up in HomeAD.

So the path goes as follows:

User Ted connects to the Main TFS using an account created for him in HomeAD, HomeAD\Ted2. He gets a token from that TFS and give it to the Proxy using his local AD creds, RemoteAD\Ted. He gets files from the Proxy, who gets the files from the Main TFS using the creds RemoteAD\proxyUser. That login gets translated into TServer\proxyUser for authentication. When Ted checks in, he uses the HomeAD\Ted2 login again.

Remote TFS

18
Dec

Web References and Debugging.

I ran into a problem today with a friend who runs a few sites like PhoneDog.com and ButterflyEffects.com. He had an issue with page loads being very very slow for no reason at all. We must have spent two hours looking into firewall, vpn, network and server issues. None of them were found to be the issue. All we knew was that it ran like greased lightning when we were on the local network of the host server. A little more tested showed that it seemed to be the cached files not being cached. Even though IE and FF were set to cache the files, it seemed like they were being downloaded every time.

Well I finally discovered that when a .NET site is set to debug, the web reference files are set to private. And because of that they are re-downloaded every time. This is no big deal, but when you use a lot of controls like Rad Grid and compiled images they load the server up horribly. You can see over 1 MB being downloaded on every page. And NONE of that shows up in the source code. You see you have a 80k source code size, but if you open you temp files you will find a Meg of files downloaded every time.

Well, in a 2.0 site, just open the web.config, find the debug section and set it to false. That will mark the web references are public and cacheable.

<compilation debug=”false”>

Enjoy