oibo8x / subsonicproject

Automatically exported from code.google.com/p/subsonicproject
0 stars 0 forks source link

Inconsistent behavior with SqlQuery.ExecuteSingle<T> #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. try to load a non-existent record using old query (Query class), we get
an object with "IsLoaded = false"
2. try to load the same record using DB.GET<T>, we also get an object with
"IsLoaded = false"
3. however try to load the same record with .ExecuteSingle<T>, we get "null"

What is the expected output? What do you see instead?
Isn't execute single consistent with older query & Get method?

What version of the product are you using? On what operating system?
SubSonic 2.1

Please provide any additional information below.

Original issue reported on code.google.com by ylw...@gmail.com on 12 Nov 2008 at 8:19

GoogleCodeExporter commented 9 years ago
I have the same problem.
SubSonic.SqlQuery sqlq = new SubSonic.Select()
.From(Dal.VwPage.Schema)
.Where(Dal.VwPage.Columns.CeuCountryWebsite).IsEqualTo(cduCountryWebsite)
.And(Dal.VwPage.Columns.TxTemplateUrl).IsEqualTo(url);
Dal.VwPage = sqlq.ExecuteSingle<Dal.VwPage>();

Windows XP, Sql Server 2005, asp.net 2.0, SubSonic 2.1 Final

Original comment by ricardoc...@gmail.com on 9 Feb 2009 at 12:51

GoogleCodeExporter commented 9 years ago
ExecuteSingle<T> returns default(T) if there's no record found which is null 
for 
reference types. I'm not a big fan of the null object pattern so I would prefer 
the 
ExecuteSingle behavior be replicated with DB.Get<T> since I always have to 
handle empty 
objects myself. Just my $.02

Original comment by rimsyst...@gmail.com on 1 Apr 2009 at 3:54

GoogleCodeExporter commented 9 years ago
Oops, posted the previous comment under the wrong account. Anyway, there's a 
conflict 
here with Issue 20 who wants the opposite of what you want.

Original comment by johnshee...@gmail.com on 1 Apr 2009 at 3:56

GoogleCodeExporter commented 9 years ago
I've moved to returning null if object not in DB - closing

Original comment by robcon...@gmail.com on 9 Apr 2009 at 2:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
therefore, does it mean that "IsLoaded" property is pretty much useless? this 
really
is not a big deal but it breaks backward compatibility. wherever we use 
"x.IsLoaded"
to check the object existance we have to change to "x != null" otherwise an 
exception
will be thrown.

Original comment by ylw...@gmail.com on 13 Apr 2009 at 5:32

GoogleCodeExporter commented 9 years ago
Ugh - yah I thought about it but it's better design. Interesting discussion...

Original comment by robcon...@gmail.com on 13 Apr 2009 at 6:08