LINQ issue

0 views
Skip to first unread message

Greg

unread,
Nov 23, 2009, 6:08:09 AM11/23/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have a program that I am starting to write that uses LINQ to fetch
SQL information.
I add a Linq to SQL class and it is called site with the Site ID being
the primary key that is an autogenerated number and the SiteName which
is a varchar(50). Neither field allows nulls.

so now the code giving me an issue

Site db = new Site();
var query = from sn in db.SiteName //<===== This line is
erroring out
select sn;


With the error
ArgumentNullException was unhandled
Value cannot be null.
Parameter name: source

I do not understand why this is happening. I am just quesrying the
data (only 3 items in table)

Can anyone explain to me what am I missing here?

Gunawan Hadikusumo

unread,
Nov 23, 2009, 4:22:38 PM11/23/09
to dotnetde...@googlegroups.com

 Site db = new Site();
           var query = from sn in db.SiteName _   <=you forgot underscore, mate !
           select sn;

Cerebrus

unread,
Nov 24, 2009, 1:00:41 AM11/24/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Underscore ? This is C#, if I'm not mistaken.

On Nov 24, 2:22 am, Gunawan Hadikusumo <john.hadikus...@gmail.com>
wrote:

Processor Devil

unread,
Nov 24, 2009, 3:46:52 AM11/24/09
to dotnetde...@googlegroups.com
hard to say... :D

2009/11/24 Cerebrus <zor...@sify.com>

Gunawan Hadikusumo

unread,
Nov 24, 2009, 1:17:40 AM11/24/09
to dotnetde...@googlegroups.com
Sure, i got the same issue couple months back. I wanted to break the LINQ query to the new line, i forgot to put "_" (underscore) at the end of
the breaking line then i got an error message.

Down here in yellow.

        Public Shared Function GetMaxGroupedTag() As GroupedTag
            Dim m_max_tag As New GroupedTag
            Dim m_tags As CodeHotSpot.ArticleTags.ArticleTag() = CodeHotSpot.ArticleTags.Api.ReadAll(-1, CodeHotSpot.ArticleTags.Enumeration.OrderBy.ArticleId, CodeHotSpot.ArticleTags.Enumeration.SortOrder.ASC)

            Dim m_query = From t In m_tags Group t By t.Tag Into Count() _
                          Select Tag, Total = Count Order By Total Descending

            Dim m_max_query = From u In m_query _
                              Select u Take 1

            If m_max_query.Count > 0 Then
                m_max_tag = New GroupedTag(m_max_query(0).Tag, m_max_query(0).Total)
            End If
            Return m_max_tag
        End Function

Greg

unread,
Nov 24, 2009, 5:24:47 AM11/24/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I am afraid that with the information I gave made it impossible for
anyone to resolve the issue.
My mistake was the dbml was not site, but was a different name.
When I pulled the sites table into the object relational designer it
named it Site.
So I was referencing the name it gave the table by mistake.
Well, the more I fail the closer I come to success!

Looks like I owe you all a beer!
Cheers!
Greg
Reply all
Reply to author
Forward
0 new messages