PC Review


Reply
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average.

Linq-to-Sql var null question or observation

 
 
Arne Vajh°j
Guest
Posts: n/a
 
      27th Dec 2010
On 25-12-2010 10:39, Big Steel wrote:
> On 12/25/2010 10:13 AM, Registered User wrote:
>> On Sat, 25 Dec 2010 05:27:04 -0800 (PST), RayLopez99
>> <(E-Mail Removed)> wrote:
>>
>>> On Dec 25, 12:14 pm, Big Steel<(E-Mail Removed)> wrote:
>>>> On Sat, 25 Dec 2010 00:55:28 -0800 (PST), RayLopez99
>>>>
>>>> <(E-Mail Removed)> wrote:
>>>>
>>>> How is a List<T> null?
>>>>
>>>> It's a
>>>> collection. The collection can be insantiaed new and nothing put in
>>>> it. Collection.count = 0.
>>>>
>>>> That's what is coming out of the query even if you didn't use
>>>> ToList(), an empty List<T> being created.
>>>

>> Just for absolute clarity ... a List is created when ToList() is
>> invoked. A List<T> gets created when ToList<T>() is invoked.

>
>
> I don't see your point here. If more than one object is being returned
> out of the query, you don't need ToList() it's going to return a List<T>
> by itself of objects in a tubular form.
>
> A ToList() is used to force eager loading as opposed to lazy loading.
>
> <http://weblogs.asp.net/morteza/archive/2008/08/29/using-tolist-method-to-force-linq-query-execute-immediately.aspx>


Given that eager and lazy loading has very specific meaning
in ORM context and this is not quite that, then I think the
term "execute immediately" is a better term.

Arne

 
Reply With Quote
 
 
 
 
RayLopez99
Guest
Posts: n/a
 
      27th Dec 2010
On Dec 27, 8:24*pm, Arne Vajh°j <(E-Mail Removed)> wrote:

>
> A collection has to be created without new if there are data - it
> is not so surprisingly to me that it does the same with no data.
>


Yes, perhaps, but it was surprising to me.

RL

 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      27th Dec 2010
On 26-12-2010 03:18, Big Steel wrote:
> On Sat, 25 Dec 2010 23:33:36 -0800, Peter Duniho
> <(E-Mail Removed)> wrote:
>> On 12/25/10 11:30 PM, Big Steel wrote:
>> > In doing a linq query with nHibernate, one must use IList and you cannot
>> > use a List<T>, which I found strange that a List<T> could not be used.

>
>
>> I'm not sure what you mean. Maybe something specific to nHibernate
>> (which I don't use)?

>
>> List<T> implements IList. You can use an instance of List<T> anywhere
>> that an IList is required, so saying "a List<T> could not be used"
>> doesn't make sense to me.

>
> It didn't make sense to me either when I worked a project using
> nHibernate. You can't use List<T>.


Not true.

In traditional NHibernate:

..ToList<X>() returns an IList<X>
..ToList() returns an IList

> nHibernate uses its own
> implementation of Linq on the .NET platform and it returns IList.


Not true.

In NHibernate LINQ a .ToList() returns an IList<T> (actually
a List<T> that implements IList<T>, but ...).

And since the method is defined in MS code, then I can't
really see how NHibernate could let it behave differently.

Arne


 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      27th Dec 2010
On Dec 27, 8:30*pm, Arne Vajh°j <(E-Mail Removed)> wrote:

> > On Dec 27, 6:29 pm, Arne Vajh°j<(E-Mail Removed)> *wrote:


> > OK perhaps I was not using the right words. *I am using the "Drag and
> > drop" wizard of Visual Studio 2008, when working with ADO.NET or
> > Silverlight, to generate database schema, that I can set up
> > associations with, such as foreign key, etc. *Then I am querying the
> > database tables using Linq, rather than traditional SQL as I have in
> > the past. *I don't know if this is "Linq to Sql" or not but it works
> > fine.

>
> "entity data model" is EF.
>
> "LINQ to SQL classes" is guess what.


I don't know. Haven't a guess. What?


>
> > Whatever works for me is what I call sophisticated.

>
> Unusual definition.
>
> > * * * * * * * * * * * * * * * * * ** * * * As another poster
> > said there's no free "database schema" generator for NHiberate,

>
> But there is.
>
> > * * * * * * * * * * * * * * * * * ** * * * * * * * * * * *and
> > right now the 'built in' wizard of Visual Studio 2008 seems to be
> > working well enough for me.

>
> Using the built in stuff always has some advantages, because
> you do not need to integrate things yourself.
>
> And if you are spending 50 hours creating the solution, then
> spending 10 hours getting the environment working is huge
> overhead.
>


> But if you are working on a 50000 hours projects, then those
> 10 hours of integration does not matter.


But why waste time? 10 hours is 10 hours. Perhaps nHibernate is
better for "team" projects such as what you describe, taking 50k hours
of programming time--I don't know, I work for myself and code mainly
as a hobby (though I have been getting some commercial projects
lately).

RL
 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      27th Dec 2010
On Dec 27, 8:34*pm, Arne Vajh°j <(E-Mail Removed)> wrote:

> If you don't have an existing database, then the purpose
> of the database is to persist your classes. So you define
> you classes as they fit the app best. And then the tables
> are generated that fits best with the object and the given
> ORM framework. That is a lot easier, but not always possible.
>
> And to you your analogy: it makes more sense to define the
> donkey cart after the Ferrari than the Ferrari after the donkey cart.


Yes good analogy. I'll have to look into EF and see what the latest
incantation is. Does it come 'built into' Visual Studio 2010, or is
it a special download?

BTW I saw an interesting but speculative article on why Hungary
produces so many math geniuses--the nature of the Hungarian language
is so difficult--apparently it is a form of Reverse Polish Notation (I
guess like Japanese and other Asian languages) and has three different
formal tenses, not to mention certain other grammatical quirks that I
could not even understand in English, that it forces people to think
carefully before they speak--and the theory is this tends to cultivate
one's math skills more. Interesting. This was in The Economist year
end issue that also featured Hungary's famous "mini-cars" from after
WWII (motorcycle engines in a small car, some only 1.5 m high, that
seated only two people--in response to the USSR insistence that
Hungary not build full sized cars).

RL
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      27th Dec 2010
On 27-12-2010 13:45, RayLopez99 wrote:
> On Dec 27, 8:30 pm, Arne Vajh°j<(E-Mail Removed)> wrote:
>>> right now the 'built in' wizard of Visual Studio 2008 seems to be
>>> working well enough for me.

>>
>> Using the built in stuff always has some advantages, because
>> you do not need to integrate things yourself.
>>
>> And if you are spending 50 hours creating the solution, then
>> spending 10 hours getting the environment working is huge
>> overhead.
>>
>> But if you are working on a 50000 hours projects, then those
>> 10 hours of integration does not matter.

>
> But why waste time? 10 hours is 10 hours.


It may not be a waste of time.

NHibernate comes with lots of features for some of the
more interesting ORM stuff: lazy loading, caching,
inheritance mapping etc..

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      27th Dec 2010
On 27-12-2010 13:50, RayLopez99 wrote:
> On Dec 27, 8:34 pm, Arne Vajh°j<(E-Mail Removed)> wrote:
>> If you don't have an existing database, then the purpose
>> of the database is to persist your classes. So you define
>> you classes as they fit the app best. And then the tables
>> are generated that fits best with the object and the given
>> ORM framework. That is a lot easier, but not always possible.
>>
>> And to you your analogy: it makes more sense to define the
>> donkey cart after the Ferrari than the Ferrari after the donkey cart.

>
> Yes good analogy. I'll have to look into EF and see what the latest
> incantation is. Does it come 'built into' Visual Studio 2010, or is
> it a special download?


EF came with .NET 3.5 SP1 (probably VS 2008 SP1 but I am not sure).

..NET 4.0 (and VS 2010) came with big improvements for EF.

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      27th Dec 2010
On 27-12-2010 13:50, RayLopez99 wrote:
> BTW I saw an interesting but speculative article on why Hungary
> produces so many math geniuses--the nature of the Hungarian language
> is so difficult--apparently it is a form of Reverse Polish Notation (I
> guess like Japanese and other Asian languages) and has three different
> formal tenses, not to mention certain other grammatical quirks that I
> could not even understand in English, that it forces people to think
> carefully before they speak--and the theory is this tends to cultivate
> one's math skills more. Interesting. This was in The Economist year
> end issue that also featured Hungary's famous "mini-cars" from after
> WWII (motorcycle engines in a small car, some only 1.5 m high, that
> seated only two people--in response to the USSR insistence that
> Hungary not build full sized cars).


The relevance for the thread is not obvious to me.

Arne
 
Reply With Quote
 
Arne Vajh├Şj
Guest
Posts: n/a
 
      27th Dec 2010
On 27-12-2010 14:02, Peter Duniho wrote:
> On 12/27/10 10:43 AM, Arne Vajh├Şj wrote:
>> [...]
>>> It didn't make sense to me either when I worked a project using
>>> nHibernate. You can't use List<T>.

>>
>> Not true.
>>
>> In traditional NHibernate:
>>
>> ..ToList<X>() returns an IList<X>
>> ..ToList() returns an IList

>
> Is that correct? If so, then maybe that's what the person posting as
> "Big Steel" is talking about. The .NET Framework implementation of
> Enumerable.ToList<T>() returns a List<T>, not IList<T>.
>
> If NHibernate has provided its own extension methods to be used in lieu
> of System.Linq.Enumerable and those methods return IList<T> and IList,
> then of course you cannot directly assign the return value to a variable
> declared as List<T>.


Traditional NHibernate is not LINQ.

Those methods are simply methods in their IQuery interface (if I
remember correct).


>>> nHibernate uses its own
>>> implementation of Linq on the .NET platform and it returns IList.

>>
>> Not true.
>>
>> In NHibernate LINQ a .ToList() returns an IList<T> (actually
>> a List<T> that implements IList<T>, but ...).
>>
>> And since the method is defined in MS code, then I can't
>> really see how NHibernate could let it behave differently.

>
> The above two statements seem to contradict each other. If NHibernate
> LINQ returns IList<T> from ToList<T>(), then it can't be defined in
> Microsoft code, because Microsoft's code returns a List<T>, not an
> IList<T>.


Traditional NHibernate != NHibernate LINQ

> I admit, not being a user of NHibernate myself, I'm at a disadvantage in
> trying to explain the comments from the person posting as "Big Steel".
> But if NHibernate is actually providing its own LINQ methods
> implementation and it's failed to adhere to the API contract that
> Microsoft has already published, I could see how in some sense of the
> word "can't", you "can't" use List<T> with NHibernate (i.e. in that
> narrow scenario where you're trying to assign the return value from
> ToList<T>() to a variable).


As far as I can tell NHibernate LINQ works exactly like MS
intended.

IList<T1> res4 = (from t1 in s.Linq<T1>() select t1).ToList();

works.

Traditional NHibernate is not exposing a MS API, so no surprise
that it is a bit different.

That looks like:

IList<T1> res1 = s.CreateQuery("FROM T1 AS t1").List<T1>();
IList res2 = s.CreateQuery("FROM T1 AS t1").List();

Arne
 
Reply With Quote
 
RayLopez99
Guest
Posts: n/a
 
      27th Dec 2010
On Dec 27, 8:55*pm, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 27-12-2010 13:50, RayLopez99 wrote:
>
> > BTW I saw an interesting but speculative article on why Hungary
> > produces so many math geniuses--the nature of the Hungarian language
> > is so difficult--apparently it is a form of Reverse Polish Notation (I
> > guess like Japanese and other Asian languages) and has three different
> > formal tenses, not to mention certain other grammatical quirks that I
> > could not even understand in English, that it forces people to think
> > carefully before they speak--and the theory is this tends to cultivate
> > one's math skills more. *Interesting. *This was in The Economist year
> > end issue that also featured Hungary's famous "mini-cars" from after
> > WWII (motorcycle engines in a small car, some only 1.5 m high, that
> > seated only two people--in response to the USSR insistence that
> > Hungary not build full sized cars).

>
> The relevance for the thread is not obvious to me.
>
> Arne


Yeah, another study found that people like you, good in math, tend to
have very poor social skills and tend to be dyslexic. Explains the
low birth rate of Hungary and why they are heading for the dustbin of
history.


RL
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
share a form level var with app - but don't make var global? Rich Microsoft VB .NET 2 3rd Feb 2009 11:54 PM
Difference between Session["var"] and Session("var") thomson Microsoft ASP .NET 10 20th Jun 2005 02:02 PM
Difference between Session["var"] and Session("var") thomson Microsoft ASP .NET 0 20th Jun 2005 11:54 AM
Internet Exp Runtime err 91 obj var or width var not set dave Windows XP Networking 0 20th Jan 2004 04:06 PM
Threads.. Session var lost, App var ok Alvin Bruney Microsoft ASP .NET 1 2nd Dec 2003 02:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.