Category: "Programming"
Entity Framework sounds better than LINQ to SQL
Recently,I did some researches for Entity Framework and LINQ to SQL. I found Entity Framework sounds better. It got better facilities. It can generate data tables from EDX and if the tables can generate the updated classes from the database. If you are using LINQ to SQL, you need to update manually. Entity Framework sounds a more completed ORM, LINQ to SQL is only a tool to translate the objects into SQL. But I think LINQ to SQL is more lightweight.
FireBug in Server Side for .Net
Yesterday, I went to the QLD MSDN User Group Meeting. One of presenters shows his opensource project, Glimpse. That is very very cool! This project is a Server Side version of FireBug in .Net. It will add a collapsible div at the bottom of page. In the div, all about the current request, including the server variable and session id, even MVC route. That is so cool! In addition, inside your code, you can add the track and the div will show them as well. Lastly, there is a remote tab inside this div. In the remote tab, you get the request information about the other clients which are on the same application. That is very helpful to mobile development. You can go into a page in the desktop and access the request information which is from the other mobile clients, rather than directly accessing them from a mobile device. I highly recommend to spend some time on learning this project!
Windows 8 Boot Camp
I went to Windows 8 Boot Camp today. I got a lot of new information about Windows 8. First of all, Windows 8 is not just for desktop. It is for touch devices too and supports ARM CPU as well as Intel. I think Microsoft wants Windows to works in Tablet too!
Secondly, for making Windows works in touch devices, Metro UI is introduced in Windows. In old UI, that was trying to use abstract graphics as representation for physical object. Metro is completely different. This UI thinks in a digital way. It changes the way to operate Windows. There are not Windows in Metro. Instead of Tiles, Snap, App Bar, they are Context Oriented UI and is easier to operate in touch devices. At the start screen, there are a lot of square blocks which are Tiles. They will shows some information from apps to you. Snap is a lot of side bar which contains a stream of Information, such as Tweets. Also, Metro contains some new gestures to operate the system. For example, dragging the current screen to the bottom is to close the current apps. Well, those gestures are not just for the touch version, for mouse version as well. For example, using the mouse to click the top left corner means switching the apps. That is a bit hard to understand that.
Lastly, Windows 8 will integrate with MicrosoftID which is your live account. You need to login with MicrosoftID to enter Windows 8. In this way, you can bring your preference to different machines via logging with a same MicrosoftID. Also, if you wants to use Metro apps, you need to use MicrosoftID. All metro apps will get from Windows Store which is the Microsoft version apps store. This is very similar with getting mobile phone apps. You login to Windows Store with your MicrosoftID. Then you pick the app in the store. It will download the software package and install for you! This MicrosoftID concept makes Windows 8 works in a similar way as the current smart phone OS such as iOS and Android.
That is very exciting! That sounds we have an OS works in Desktop and mobile devices!
P.S. Windows 8 is still keeping the old desktop windows UI. In Start screen, that is a Tile calls Desktop. Clicking this tile, you can see a UI similar with Windows 7, but that is without "Start" button.
How to put your PC in sleep or hibernate via C#
I thought that is impossible to put your PC in sleep or hibernate via C#. I found that is incorrect! Moreover, that is very simple too, just one line of command.
Putting the PC in sleep mode
Code
Application.SetSuspendState(PowerState.Suspend, false, false); |
Putting the PC in Hibernate mode
Code
Application.SetSuspendState(PowerState.Hibernate, false, false); |
That is so simple!!!
"Invalid attempt to call Read when reader is closed" in LINQ DataContext
I got a lot of error from a LINQ DataContext, such as "Invalid attempt to call Read when reader is closed" . That is because I was using a singleton for DataContext in a multi-threads.
The codes like that:
Code
private static ExampleDataContext Context; | |
private static ExampleDataContext GetContext() | |
{ | |
if(Context == null) | |
{ | |
Context = new ExampleDataContext(); | |
} | |
return Context; | |
} |
That is not very thread-safe. A thread will close the DataContext, but others threads are still using DataContext. Then it will throw the error above.
I changed the DataContext in a pre-thread. I initialize the DataContext in each thread. The errors are gone! You also can do the DataContext in a pre-object. That is simpler.