Update Single Column In Entity Framework

by Vahid 29. April 2011 18:00

I was working with Entity Framework and I needed to update a single column of a row in the database. basically I was logging the users visit to a web site (ASP.NET). so first time user lands in the website I create a record in database and keep the id in the session. when user’s session times out I needed to update the row and set the exit time of the user. it sounded a bit difficult to do this with Entity Framework I did it this way and worked pretty well:

        public void UpdateVisit(long id, string userId)
            //id (row id) comes from the user so we create an object and assign the id
            VisitInformation visitInformation = new VisitInformation() { ID = id };
                using (var context = new TravIranLogEntities())
                    //Here we attach the object to the context and set the state to unchanged
                    context.Entry(visitInformation).State = EntityState.Unchanged;
                    //update the column(s) that you need to modify
                    visitInformation.UserId = userId;
                    //Send the informatin back to the Database

            catch (Exception ex)
                LogManager.Log("Error in UpdateVisit for user id", ex, LogMode.LogAndEmai);


Tags: ,


Perfect reference to get started with EntityFramework 4.1

by Vahid 27. April 2011 16:27

Just found these set of post in the MSDN site for getting started with EntityFramework 4.1. if you are new to entityframework this is a good point to start




WP7 (Windows Phone 7) WrapPanel

by Vahid 23. February 2011 16:16

I cannot believe that I spent half day figuring out how to wrap controls in a stackpanle control in WP7 Sad smile 

but anyway I finally came to know that I should use WrapPanel instead of StackPanel. so please don’t make my mistake and download the Silverlight toolkit for WP7 from here and then make a reference to “Microsoft.Phone.Controls.Toolkit.dll” assembly from this address:

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Toolkit\Nov10\Bin\Microsoft.Phone.Controls.Toolkit.dll

and them import the controls to your page using this command:


the toolkit has got the following controls which are really savers Winking smile

  • AutoCompleteBox
  • ListPicker
  • LongListSelector
  • Page Transitions
  • GestureService/GestureListener
  • ContextMenu
  • DatePicker
  • TimePicker
  • ToggleSwitch
  • WrapPanel



Windows Server AppFabric

by Vahid 13. February 2011 05:15

if you have been involved in the enterprise application architecture and development, for sure you have also faced the memory constraint when designing the application. the thing is that as soon as you talk about enterprise application –I mean real enterprise application- you are talking about a huge amount of data being processed and traveling between systems.  that’s when you say oops, I need to take care of this, user and my hardware cannot afford these expensive operations each and every time a request comes in. then you start thinking about caching the information somewhere. ok, some out of the box caching –i.e. ASP.net Caching- is there but we are talking about huge amount of data and keeping them on the same server as the application server would be out. and that’s the time you say Valla to keeping the data in a database. you go ahead and do it but as soon as you run the first load test with few thousand concurrent users the “sh..t” word comes out. you see the bottlenecks connecting to database, you see the performance degrade and you see that you have made your business owner to spend some good amount of money for the database licenses but you are not getting the result you were after. exactly at this point of time you would wish that there was a technology to help you out with the situation and if you have heard of Windows Server AppFabric and know it, than you feel how much you are blessed.

as of now Windows Server AppFabric  consists of two components:

  • AppFabric Hosting Services: which I haven’t worked with in any project yet and is not in my focus in this post
  • AppFabric Caching Services: which is the one I have used and appreciate a lot

basically the caching services is exactly what we need in the situations like the one I talked about because:

  • we can keep the data available as long as we want
  • it’s in memory so it’s fast, very fast
  • we don’t need any database licenses
  • it’s easy to learn and worked with
  • if you need extra memory, just need to add an other machine to the nodes
  • the machines don’t need to have powerful processing power, RAM is needed

so I personally believe all of us need to start learning about this technology as it will somehow change the way we architecture our next applications by giving us to handle more data much faster. if you want you get stared with Windows Serve AppFabric, I would suggest to download the free training kit from Microsoft and get started today.


for quick guide about the installation you can refer to the following link:



.Net | Technical

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format

by Vahid 8. February 2011 11:32

I  had deploying an asp.net application to a windows 2008 64bit server. the application uses odp.net to connect to an oracle database. but when I tried to access it I kept getting an error saying:

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format”

pulling my hair for sometimes I couldn’t find any logical explanation for this as the dll named ‘Oracle.DataAccess’ was already there in the bin folder. but for some odd reason this was the problem itself. I had to delete the dll from the folder to have the application working.

I don’t have any explanation for this as of now but will update this post as soon as I figure out the cause.


.Net | Technical

First Tip On SharePoint 2010

by Vahid 29. December 2010 15:14

recently I got involved in a SharePoint project. I am not a SharePoint pro but I have the opportunity to work with some of best SharePoint professionals so I am learning as I go.

I thought it would be useful to share what I learn. although some of them maybe basic but I am sure they would help somebody out there who is just picking up on SharePoint.

So first tip would be on working with CSS files. you when I wanted to change something in CSS I was doing this stupid work of doing the changes and publishing the site/web part to see the result. because of the size of the project this was a time consuming task. but Mr. Z suggested a trick to work on the css file and change them in place where the changes would reflect without deployment.

here is the trick. Go to you 14 hive folder. it should be at the following address on your computer

C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\14

in the 14 hive find the css folder and in the folder find the css file you want to work on. open the file with you desired css editor and start editing the file. once done just save it and refresh you browser. boom here you go seeing the changes without deploying the file.

but remember to copy and paste the content of the css file into your development copy in visual studio when you are done with changes.


.Net | Learning resource | Technical

do we use silverlight when HTML 5 is out?

by Vahid 2. September 2010 05:26
This has been a question for me for sometimes. Although i knew silverlight is the future but i could never form a concrete answer to why silverlight is the future. till i came across the following blog post by the silverlight team. Make sure you read the post since it's written what is in most of our minds but cannot stated in words.




.Net | Technical

T4 to rescue and save you time

by Vahid 11. June 2010 05:56

till yesterday i had never used T4 for a real problem solving. i knew what it is but i did not know how great and easy it is.

in my current scenario i have a database table which contains options available for each property of 30 available properties of items to be added to the system. the table has almost 500 records.  in the item registration page i had to create a structure like this for each property:

<div id="div1" runat="server" class="row">
<asp:Label ID="SmartLabel13" runat="server" AssociatedControlID="" Text="Title of the property"></asp:Label>
<asp:DropDown ID="SmartDropDown1" runat="server">
<asp:ListItem Selected="True" Text="-----------" Value="">
<asp:ListItem Selected="True" Text="option 1" Value="option 1 value">
<asp:ListItem Selected="True" Text="option 2" Value="option 2 value">
<asp:ListItem Selected="True" Text="option n" Value="option n value">

creating 50 of these snippet and adding almost 12 list item for each of them along with setting the control names and property title and also AssociatedControlID of each would have taken me at least a day. i thought i could benefit from T4(Text Template Transformation Toolkit which is used for code generation) to save myself some time. so i started creating a T4 file to do this and vala… 15 minutes later i had it done. i have to say that, it was the first time that i actually was using T4. i cannot believe how easy it is to use it. the following few lines of code saved me at least a day by generating around 1000 lines of code:

<#@ template language="C#" debug="True" #>
<#@ output extension="txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#@ import namespace="System.Data.SqlClient" #>
string catName=string.Empty;
int i=50;
System.Data.SqlClient.SqlConnection cn=new  System.Data.SqlClient.SqlConnection("data source=.\\sqlexpress;integrated security=true;database=Irizzle");
SqlCommand cmd=new SqlCommand("select * from IRZ.Lookupvalues order by Category",cn);
SqlDataReader dr=cmd.ExecuteReader();
<asp:ListItem Text="<#= dr["Name"].ToString()#>" Value="<#= dr["Code"].ToString()#>" />
<div id="div<#= dr["Category"].ToString()#>" runat="server" class="row">
<label for="drp<#= dr["Category"].ToString()#>"><#= dr["Title"].ToString()#></label>
<Irizzle:SmartDropDown ID="drp<#= dr["Category"].ToString()#>" runat="server">
<asp:ListItem Selected="True" Text="-----------" Value=""/>
<asp:ListItem Text="<#= dr["Name"].ToString()#>" Value="<#= dr["Code"].ToString()#>" />
<#    i++;}

i am sure T4 can save you and your companies hell lot of time. what i am wondering about is why not so many people talk about this great feature.

Tags: , ,

.Net | Technical

Waht is new in silverlight 4.0

by Vahid 21. April 2010 05:39

i have found a perfect blog post from mr. tim heuer on new features in silverlight 4.0. it's definitely worth going through his post.



.Net | Learning resource | Technical

Assign a static port to Asp.net Website

by Vahid 15. December 2009 08:04
A while ago in a project we had the requirement to assign a static port number to our asp.net website project. The very first thing came to my mind was that we just can assign static port number to asp.net web application project type and we cannot assign a static port to asp.net web site project. Anyway I started searching in the internet for a solution to make sure about it. I spent quit a long time looking for an answer but I could not find any almost everywhere it was mentioned that we cannot assign a static port to a asp.net website and it is constrained to use dynamic port.I was convinced at the time and we managed to convert to asp.net web application. Surprisingly recently a friend of mine, Ali, referred a perfect solution for this issue to me and I thought it’s worth sharing with you. Step 1- the very first step is to add the asp.net Web Server external tool to Visual Studio. To do so
  • go to the Tool menu
  • Click on the External Tool menu


Step 2- next step is to actually adding the external tool. Once the external tool window is open, click on Add button and
  • In the title text box give your web server a name (in this case I have called it webserver 1919).
  • In the command text box enter your .net web server address (in my computer it is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE)
  • In the Arguments text box enter /port:{port number} /path:$(ProjectDir) where {port number} is your desired static port number (in this case I have chosen port 1919 and the value is “/port:1919 /path:$(ProjectDir)”).
  • Tick use output window check box
  • Click on the Ok button


Step 3- now that the external tool is added and ready to use you have to change your asp.net website project setting to use this web service rather than default web service. To do so
  • Right click on your asp.net project file and click on the Property Pages menu.
  • On the left side of the property window click on Start Options.
  • In the Server section choose Use custom server
  • In the base URL text box enter http://localhost:1919 where 1919 should be the port number you have chosen in step 2
  • Click on the Ok button


Step 4- the last step is to start the custom web server before debugging the application. To do so:
  • Click on the Tool menu. Now a new menu item having the name you have assigned to the customer web server in step 2 should be displayed in the tool menu.
  • Click on the new menu item (in this case webserver 1919)

Now you are ready to go. Click F5 and start debugging your asp.net web site on a static port.