In VS2010 when you type the dot and then an E you will not get Equals in intellisense as an option. You have to either type the q too or go to the All tab. I also noticed I can’t change the Hide advanced members anymore. It seems to be unchecked by default. I still think the equals method is something every OO-developer should use and know how and why to use it. If you don’t, then look it up.
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
I’m using NHibernate version 2.1.2 GA and the 2.1.2 Linq version that goes with it. And I like to state that I’m not complaining, but perhaps I can save some people from losing too much time while trying this. You still have plenty of other options if Linq does not work in your situation. So let’s say I have this Person Object Public Class Person Private _name as String Private _addresses as Ilist(Of Address) ... End Class``` And as we see in the above, also a Class Address ```vbnet Public Class Address Private _straat as String ... End Class``` I won’t bore you with the mapping file because they are straightforward. The thing I want is to have all the address for persons with a name beginning with A (I know it’s stupid but that’s not the point) So I have this HQL that works nicely. ```vbnet _Query = _Session.CreateQuery("SELECT elements(p.Addresses) FROM Person p WHERE p.Name LIKE 'A%'") _ReturnObject = _Query.List(Of Address)()``` This should return me a nice list af Addresses where a Person has a name starting with A (so now the callcenter can start calling those persons ;-)) I cannot make a one statement Linq for this. The closest I got is this: ```vbnet Dim _Query = From e In _Session.Linq(Of Person)() Where e.Name.StartsWith("A") Select e For Each person In _Query For Each address In person.Addresses _ReturnObject.Add(address) Next Next``` The next thing I found not to be working is Nullables For example, if you have this Class ```vbnet Public Class Person Private _birthDate as Nullable(Of Date) ... End Class Considering that BirthDate could be empty (I know, I know but work with me here).
So today I wanted to transfer one of my VM’s from my local machine running under VMWare Workstation 7 to a brandnew ESXi 4 server we have laying around. First I thought I would just copy the data to the datastore and open the VM from there but that gives you this error. “Failed to open disk scsi0:0: Unsupported and/or invalid disk type 7. Did you forget to import the disk first?Unable to create virtual SCSI device for scsi0:0, ‘/vmfs/volumes/*\**randomID**/blahblah.vmdk’ Module DevicePowerOn power on failed.
You see this kind of question all the time in newsgroups/forums, someone wants to return all the rows if nothing is passed in or just the rows that match the variable when something is passed in. Usually someone will reply with a suggestion to do something like this WHERE (SomeColumn=@col OR @col IS NULL) The problem with that approach is that it doesn’t perform well, let’s take a look, first create this table
The work and wait is almost over SQL Saturday in Chicago is only days away now and the excitement is building. I feel an explanation is in order for my lack of contributions to the SQL community the last few weeks. SQL Saturday has taken a lot time to work on coupled with the normal daily work schedule. Last minute preparations are going well and I think all of the attendees, speakers and sponsors will be very happy with how the event will come together.
Today I opened up my solution in VS2010 and did the upgrade, which according to the upgrade wizard was a minor thing. All projects are still compiled against the 3.5 framework. So there should not be any difference. And Still… it crashed. Well it wasn’t really me, but Something in the resx from a third party. And the error is very descriptive too. Error 2 The type initializer for ‘Atalasoft.Imaging.AtalaImage’ threw an exception. Line 133, position 5. E:Visual studio projectsTDB2009ProjectsTDB2009.ViewKitManagementViewDialogsfrmScanReciepts.resx 133 5 TDB2009.View
Ok, time to try the linq to nhibernate subquery possibilities. Let’s say I have a object called TexCase that has a collection of Tags Of Type Tag. And the Class Tag has a property called Tag of type string. So I have this HQL query. _Session = SessionFactory.OpenSession _Query = _Session.CreateQuery("select i from TexCase as i join i.Tags t where t.Tag like :Tag") _Query.SetString("Tag", ToFind) _ReturnList = _Query.List(Of TexCase)() ``` Where ToFind is a String (obviously). In this case the string can contain wildcards. Not sure if that is a good idea, but anyway. So, * %s * s% * %s% should all work. And [NHProf][1] also confirms it. ```tsql and x1_.Tag like '%s'``` ```tsql and x1_.Tag like 's%'``` ```tsql and x1_.Tag like '%s%'``` The linq query looks something like this. ```vbnet _Session = SessionFactory.OpenSession Dim _query = From e In _Session.Linq(Of TexCase)() Where e.Tags.Any(Function(x) x.Tag.Contains(ToFind)) _ReturnList = _Query.ToList``` But that’s not completely true since the above will give us the following sql. ```tsql and x1_.Tag like '%s%'``` ```tsql and x1_.Tag like '%s%'``` ```tsql and x1_.Tag like '%s%'``` Yes, the same for all three tests. To solve that I needed to do. ```vbnet _Session = SessionFactory.OpenSession Dim _query As IEnumerable(Of TexCase) If ToFind.StartsWith("%") AndAlso ToFind.EndsWith("%") Then _query = From e In _Session.Linq(Of TexCase)() Where e.Tags.Any(Function(x) x.Tag.Contains(ToFind.Substring(1, ToFind.Length() - 2))) ElseIf ToFind.StartsWith("%") Then _query = From e In _Session.Linq(Of TexCase)() Where e.Tags.Any(Function(x) x.Tag.StartsWith(ToFind.Substring(1))) ElseIf ToFind.EndsWith("%") Then _query = From e In _Session.Linq(Of TexCase)() Where e.Tags.Any(Function(x) x.Tag.EndsWith(ToFind.Substring(0, ToFind.Length() - 1))) Else _query = From e In _Session.Linq(Of TexCase)() Where e.Tags.Any(Function(x) x.Tag.Equals(ToFind)) End If _ReturnList = _query.ToList``` Eeck. Not pretty. But I think I can make this work better over time. [1]: http://nhprof.com/
Today I thought it would be good to try some Linq to nHibernate while I was waiting for VS2010 to finish downloading. First thing I had to do was download [NHibernate 2.1.2 GA][1] and [the Linq provider][2] that goes with it. I was using 2.0.1 up until now. So I had to add a [Bytecode provider to my configuration][3] routine. That wasn’t too difficult (I thought). This was the line I used.
Visual Studio 2010 and Microsoft .NET Framework 4 will be available for download later today on MSDN. Right now it looks like the time that it will be available is 10 AM PDT. Now when it is available on MSDN don’t just download it from the first place you see it, check Top Downloads first ( http://msdn.microsoft.com/en-us/subscriptions/bb608344.aspx ) The top downloads page uses Akamai and the downloads are much faster than the regular MSDN downloads.
Long ago I came across OldSchoolDotNet’s Silverlight Sudoku client. It’s a great interface to a classic brain game. I especially enjoy the “Hard” difficulty level as it is pretty consistently solvable with out reverting to guessing. The “Expert” level though requires you to guess. And as a logic guy, I hate guessing. Not quite so long ago, in the Programmer’s Puzzles forum, we had a “Follow the Clues” challenge. I approached this problem just as I do Sudoku. Writing out the possibilities and eliminating the incorrect answers as I went through the rules list over and over. But just solving the problem isn’t enough, the goal, seeing as how most of us are coders of one sort or another, is to write a software solution. So I put together a system that given an array of possibilities and a set of rules, would iterate through the rules and grid filtering out all impossible answers till only the correct ones existed.