If you want to use the SaveOptions.None, when calling the method DbContext.SaveChanges, you must override de function in a partial class, like:
/// <summary> /// </summary> public partial class MyEntities : IMyEntities { /// <summary> /// Dynamically set connection string and configure Entity Framework. /// </summary> /// <param name="connection"></param> public Myntities(string connection) : base(connection) { // Set Configuration.AutoDetectChangesEnabled = false to improve performance (100x). Configuration.AutoDetectChangesEnabled = false; // By default use lazyloading. Configuration.LazyLoadingEnabled = true; // Don't valid entities on save. Configuration.ValidateOnSaveEnabled = false; } /// <summary> /// Override the default save changes so, because we have disabled "AutoDetectChangesEnabled". /// </summary> /// <returns></returns> public override int SaveChanges() { return (this as IObjectContextAdapter).ObjectContext.SaveChanges(System.Data.Objects.SaveOptions.None); } }
Tags: Entity Framework
I wanted to convert a XML based on attributes to a XML based on child nodes, e.g.:
Input
<?xml version="1.0" encoding="utf-8" ?> <people> <person firstname="John" lastname="Smith"/> <person firstname="Michael" lastname="Johnson"/> <person firstname="Jacob" lastname="Williams"/> </people>
Output
<people> <person> <firstname>John</firstname> <lastname>Smith</lastname> </person> <person> <firstname>Michael</firstname> <lastname>Johnson</lastname> </person> <person> <firstname>Jacob</firstname> <lastname>Williams</lastname> </person> </people>
XSLT
The forum post [http://stackoverflow.com/questions/6496334/c-sharp-to-convert-xml-attributes-to-elements] contains a XSLT script that will just do that.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.something.com"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:variable name="vNamespace" select="namespace-uri(/*)"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="*/*/@*"> <xsl:element name="{name()}" namespace="{$vNamespace}"> <xsl:value-of select="."/> </xsl:element> </xsl:template> <xsl:template match="x:Value"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> <xsl:apply-templates select="@*"/> </xsl:template> </xsl:stylesheet>
Tags: XSLT
When you use DbContext.Configuration.AutoDetectChangesEnabled = false to improve performance, then there will be no automatically state tracking (this is what’s causing the performance penalty). To update a entity in the database, including it’s releated entities (navgiation properties), you should use the Entry function on the DbContext:
using System.Data.Entity; using System.Linq;
[TestMethod] public void TestChangeTrackingEF() { using (var entities = new MyEntities()) { // Set Configuration.AutoDetectChangesEnabled = false to improve performance (100x). entities.Configuration.AutoDetectChangesEnabled = false; // By default use lazyloading. entities.Configuration.LazyLoadingEnabled = true; // Get a specific entity from the database var query = from i in entities.ImageInfo where i.Id == 41 select i; ImageInfo info = query.First(); // Update the entity info.ProcessStatusId = 9; // Set state to Modified entities.Entry(info).State = System.Data.EntityState.Modified; // Save changes to the database. entities.SaveChanges(); } }
Tags: Entity Framework
From a developers perspective, developing metro style applications in Windows 8 is all about app contracts.
One of the contracts is the sharing contract, this allows apps to share data without knowing up front to which apps it will connect. This contract also allows sharing by using NFC (near field communication), without the developer knowing anything about NFC.
The cool thing about this is that, Windows 8 will start sharing data between 2 devices, when they are in reach of the NFC radio and you give permission by tabbing the two devices together.
What’s even cooler is the fact that after the initial “handshake”, the communication channel can be automatically upgraded to use Bluetooth, Wi-Fi or Wi-Fi direct.
So imaging, if you put two brand new Windows 8 ivy bridge tablet with NFC together, they can share music, video or picture files directly by using it’s 802.11AC 1 wireless adapters. Wireless sharing this data at 1gbit\s.
See the following screencast for more information:
http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-270T
Connecting and sharing with near field communication
Tags: NFC
Let’s assume you have a table Customer in a Microsoft SQL Server database:
And want to delete Customer_008, Customer_009, Customer_010, Customer_011 based on a generic list in C#, you can join this generic list with a entity dbset in entityframework 4.2:
NOTE: For best performance start the query with the generic list and then join on the Customer table.
[TestMethod] public void RunNewCodeTest() { TestBulkDelete(); } private void TestBulkDelete() { // Define customers to delete in a generic list of strings. var names = new List<string>(); names.Add("Customer_038"); names.Add("Customer_039"); names.Add("Customer_040"); names.Add("Customer_041"); using (var entities = new Rvl.NewCode.Model.NewCodeEntities()) { // To improve performance by a factor 1000, set Configuration.AutoDetectChangesEnabled = false. entities.Configuration.AutoDetectChangesEnabled = false; // Get customers to delete. var query = from name in names join customer in entities.Customer on name equals customer.Name select customer; List<Customer> customersToDelete = query.ToList(); // Delete customers from context. foreach (Customer customer in customersToDelete) { entities.Customer.Remove(customer); } // Delete customers from database. entities.SaveChanges(); } }
Tags: C#, Entity Framework
The first thing you might ask me, is Scrum / Agile development and XP the holy grail of software engineering? The answer is: As always “NO”, for each software development technique or tool there are exceptions of when an when not to use them.That said, these are the best software development techniques I encountered so far and I encourage you to read the free e-book Scrum and XP from the Trenches – How we do Scrum.
Some key takeaways
Is there one true way, to do Scrum / Agile and XP and the answer is….again: NO. This book just describes the way Henrik Kniberg and his team do scrum. Do you work on a product with severe quality problems, are you constantly firefighting or miss deadlines more then meeting the deadlines, then scrum might be something for you, if you really complete the implementation.
Scrum / XP teams
Don’t have time for theories.
They don’t write code that will be able to accommodate all imaginable future changes.
They focus on "Getting things done".
Sprints
Are designed to be short and time boxed.
Sprint planning
The purpose of the sprint planning meeting is to give the team enough information to be able to work in undisturbed peace for a few weeks, and to give the product owner enough confidence to let them do so.
Sprint backlog
The sprint backlog to the right is a snapshot of stories from the product backlog. The team decides how many stories to include in the sprint. Not the product owner or anybody else.
XP Programing
Is not only about pair programming, it’s all about: Simple Design, Pair Programming, Test-Driven Development and Design Improvement (refactoring).
Story points
Backlog items are measured in story points. A story point corresponds roughly to "ideal man-days"
Product owner
If the product owner has a technical background he might add stories such as “Add indexes to the Events table”. In that case ask the product owner a set of “but why” questions until the underlying goal is clear, e.g.: “speed up the search event form in the back office”
The team is normally better suited to figure out how to solve something, so the product owner
should focus on business goals.
Assigning importance level to stories is the sole right.
Team
Assigning time estimates is the team’s sole right, so the product owner or other people may not assign time estimates to stories.
External and Internal quality
• External quality is what is perceived by the users of the system. A slow and non-intuitive user interface is an example of poor external quality.
• Internal quality refers to issues that usually aren’t visible to the user, but which have a profound effect on the maintainability of the system. Things like system design consistency, test coverage,
code readability, refactoring, etc.
Poor external quality can make perfect business sense (releasing a better version later) and this quality can be determined by the product owner. Internal quality, however, is not up for discussion. It is the team’s responsibility to maintain the system’s quality under all circumstances and this is simply not negotiable. Ever.
The word “quick-fix” should trigger an alarm in your head… Nothing is more permanent, then a temporarily solution.
Definition of “done”
It is important that the product owner and the team agree on a clear definition of “done”. Is a story complete when all code is checked in? Or is it complete only when it has been deployed to a test environment and verified by an integration test team? Whenever possible we use the done definition “ready to deploy to production” but sometimes we have to
make do with the done definition “deployed on test server and ready for acceptance test”.
Test driven development
Test driven development, which in effect means that the first task for almost each story is “write a failing test” and the last
task is “refactor” (= improve code readability and remove duplication).
Seat the team together
What does this mean: Well, anybody in the team can talk to anybody else without shouting or leaving his desk. Everybody in the team can see everybody else.Everyone can see the taskboard. Nobody outside the team is close enough to be disturbed. And vice versa. What about distributed teams? Well if you really, really haven’t got a choose and some team members work from an other place, use tools that accomplish the rules above e.g. use a skype like tool and leave it open at all times, including camera and audio!
Always coach people, don’t break them into peace’s and don’t coach in front of the whole team!
Some manager work exactly the other way around, breaking people in front of the team and afterwards call this person to soften the edges. Well, this may work for some people, I personally find this counterproductive and most people will give this manager the finger (most of the time in there own minds, but non the less).
Do sprint demo’s
Doing a demo forces the team to actually finish stuff and release it (even if it is only to a test environment). Without demos, you keep getting huge piles of 99% finished stuff.
Do sprint retrospectives
Because this is your best chance to improve. Without retrospectives you will find that the team keeps making the same
mistakes over and over again.
Plan time between sprints
In real life, you can’t always sprint. You need to rest between sprints. If you always sprint, you are in effect just jogging. At the very least, we try to make sure that the sprint retrospective and the subsequent sprint planning meeting don’t occur on the same day. Everybody should at least have a good night’s sprintless sleep before starting a new sprint.
One way to accomplish this is by introducing “lab days”. That is, days where developers are allowed to do essentially whatever they want. For example read up on the latest tools and APIs, study for a certification, discuss nerdy stuff with
colleagues, code a hobby project, etc.
Note: this post will be updated during the next 2 weeks.
Just want to share a screen dump of the new Microsoft Windows 8 extraction progress window:
Tags: Windows 8
After using VirtualBox and VMWare workstation for running my Windows 8 virtual machines, I seems like VMWare workstation is the winner at this point in time for me.
So here’s the installation guide for creating a Windows 8 VMWare workstation virtual machine.
File > New Virtual Machine… >
Remove floppy and printers
Use the Windows8.iso as DVD:
Install VMware tools.
Tags: VMWare
- Install Oracle VirtualBox v4.0.8
- Start Oracle VirtualBox v4.0.8
- Choose VHD (Virtual Hard Disk) for compatibility with Microsoft Hyper-V
Enable PAE/NX
Enable 3D acceleration
Enable 2D video acceleration
Enable SSD (if you have a SSD)
Add Windows 8 i*.iso as CD/DVD drive:
Use bridged networking.
Drive options
New
Install guest additions…
- Open the cd in explorer
- Right-click on VBoxWindowsAdditions-x86 (or -amd64 for 64-bit Windows
and select Properties. - Under the Compatibility tab set the compatibility mode to ‘Windows 7′.
- Double-click the file to install, and don’t select the 3D driver or the install will fail.
Tags: VirtualBox

