Voting has been open for a few days now for which lectures will be featured at the next Microsoft Developers' Academy. The event is the second most important event for Microsoft-platform-developers in Israel, surpassed only by the biennial Tech-Ed Israel.
Among some very interesting lectures I would love to see, I've suggested a lecture myself. Here's its abstract:
A Deep Dive into LINQ
Many developers already use LINQ on a daily basis, but most only scratch the surface of what’s possible. In this session we will dive more deeply into LINQ and see how it works behind the scenes, share tips, tricks and common pitfalls.
While most of the lecture's structure is already defined in my head, I'd love to hear from you what topics you would like to see covered, either from the topics covered in my blog's posts or from your own experience.
Go vote and I'll be seeing you there! :)
After a couple of days of trying to run a load test for a web service on several agents via Visual Studio 2008, I come out much wiser and with a few new bald-spots, where hair I pulled out in the process used to be.
I got a few errors whose messages have nothing to do with what really happened, so here's a quick checklist:
- Try restarting the agent service.
- Re-register the agent using AgentConfigUtil and then restart the agent service.
- Try restarting the controller service.
- Are you using a trial version of Visual Studio Team System? If so, it may have expired.
- Are all of your agents and controller on the same version?
Check that the file Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll is the same version on all of your computers (more information). Its original version is 9.0.21022.8, SP1's version is 9.0.30729.1. If you installed the trial from Microsoft's site, your version is pre-SP1.
If any of the agents differs from the controller, you will not be able to use them and will see them as Disconnected in the Administer Test Controllers dialog. - Are you using SQL Server as a store for the results?
- Does the user the service runs as have permissions to the SQL Server database?
You can see which user is used to access the store from Visual Studio's Menu Test -> Administer Test Controllers. - If you're getting login errors, check that the SQL Server allows remote connections. If it does, consider using a SQL Server user instead of Windows Authentication. Remember to make sure the SQL Server allows both types of connections (Mixed Mode) before attempting this.
- Make sure the computer from which the SQL Server is running has an exception for incoming connections on TCP port 1443.
- Using the trial version of the agents? Getting "The Visual Studio Team Test Load Agent license has expired" way before your 90 day trial period has elapsed? You've probably hit the 25 tests mark (note that the tests are per-CPU, rather than per-computer).
You can work around this if you change the user running the service.
Around that time I decided I've had enough with all this trial stuff. I was thinking about purchasing licenses, but then I took a look and found that you can only use load agents when you've got a Volume License!
At that point, I went and just ran the test on a few computers at once.
One of the nice things about LINQ to SQL is the ability to extend the types of the generated entities. Another nice thing is being able to get typed results from stored procedures. Let's try and combine the two together.
We'll take the following generated code for instance:
public partial class GetStuffResult
{
private int _Id;
private string _Name;
public GetStuffResult()
{
}
[Column(Storage="_Id", DbType="INT NOT NULL")]
public int Id
{
get
{
return this._Id;
}
set
{
if ((this._Id != value))
{
this._Id = value;
}
}
}
[Column(Storage="_Name", DbType="NVarChar(100)")]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this._Name = value;
}
}
}
}
I would like to extend it by adding a new property to it, named TranslatedId, which translates the returned Id to and from a Guid:
partial class GetStuffResult
{
public Guid TranslatedId
{
get
{
return Translator.GetGuid(this.Id);
}
set
{
this.ProjectId = Translator.GetInt(value);
}
}
}
Translator's two methods translate between the integer id and the Guid id. Note that 0 translates to and from an empty Guid.
I'll try to run it and will find out that all of my Ids are 0. Why is that?
Apparently, when running a stored procedure in LINQ to SQL, it requires all of the properties defined on the class to have both getters and setters (which means you can not write read-only properties in the partial class) and sets all non-result (i.e. non-generated) properties to their default values. This means that although the real Id gets selected from the database, TranslatedId gets set to an empty Guid immediately afterwards, which in turn overrides Id to 0.
To work around this, we have to apply a dirty little hack:
partial class GetStuffResult
{
private Guid dupe;
[Column(Storage = "dupe")]
public Guid TranslatedId
{
get
{
return Translator.GetGuid(this.Id);
}
set
{
this.ProjectId = Translator.GetInt(value);
}
}
}
This is pretty horrible, but what it does is direct LINQ to SQL to set the default value into the property's storage field, which is some dupe field, instead of into the property itself. Now the field's value will be reset and not the property's. Note that the dupe field's type should be the same as the property's type.
Yes, it's ugly, but this is the only workaround I found. If anyone knows of any other workaround or solution to this problem, I'd love to hear it.
[Original image used: Where do we go next?]