Question to Function

Hi,
I got these
Error	21	'SalesQtyOfWeek' is not a member of 'KongTaiToolbar.YearlySalesByShoesTypeMonth'.	
Error	22	'SalesAmountOfWeek' is not a member of 'KongTaiToolbar.YearlySalesByShoesTypeMonth'.	

Open in new window

due to the codes below
...
Public Class YearlySalesByShoesTypeShoesType : Inherits List(Of YearlySalesByShoesTypeMonth)
    ...
    Public Function SalesQtyOfWeek(weekNumber As Integer) As Integer
        Return (From p In Me Select p.SalesQtyOfWeek(weekNumber)).Sum
    End Function

    Public Function SalesAmountOfWeek(weekNumber As Integer) As Double
        Return (From p In Me Select p.SalesAmountOfWeek(weekNumber)).Sum
    End Function

Open in new window

but if I've added them to the relevant class below
Imports System.ComponentModel
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Windows.Forms
Imports System.Linq
Imports System.Xml.Linq

Public Class YearlySalesByShoesTypeMonth
    ...
    Public Function SalesQtyOfWeek(weekNumber As Integer) As Integer
        Return (From p In Me Select p.SalesQtyOfWeek(weekNumber)).Sum
    End Function

    Public Function SalesAmountOfWeek(weekNumber As Integer) As Double
        Return (From p In Me Select p.SalesAmountOfWeek(weekNumber)).Sum
    End Function
...

Open in new window

I get these
Error	12	Expression of type 'KongTaiToolbar.YearlySalesByShoesTypeMonth' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
Error	13	Expression of type 'KongTaiToolbar.YearlySalesByShoesTypeMonth' is not queryable. Make sure you are not missing an assembly

Open in new window

LVL 11
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naitik GamitSoftware DeveloperCommented:
try to add namespace  System.Data.Linq

OR

 just call AsQueryable()
0
HuaMin ChenProblem resolverAuthor Commented:
Sorry, "System.Data.Linq" is not available below

https://dl.dropboxusercontent.com/u/40211031/tt300.jpg

where to put "AsQueryable()"?
0
Naitik GamitSoftware DeveloperCommented:
Put AsQueryable() at end of your linq query like:

var objemp=dbcontext.where(c=>c.empid==3).AsQueryable();
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

HuaMin ChenProblem resolverAuthor Commented:
Should I add "AsQueryable()" to Functions in above? If yes, how?
0
HuaMin ChenProblem resolverAuthor Commented:
Any advice?
0
Naitik GamitSoftware DeveloperCommented:
0
HuaMin ChenProblem resolverAuthor Commented:
I cannot choose

System.Data.Linq

below. why?
6b
0
HuaMin ChenProblem resolverAuthor Commented:
I've done the proper import like
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Linq
Imports MySql.Data.MySqlClient
Imports System.Windows.Forms
Imports System.Linq
Imports System.Xml.Linq

Public Class YearlySalesByShoesTypeMonth
...
    Public Function SalesQtyOfWeek(weekNumber As Integer) As Integer
        Return (From p In Me Select p.SalesQtyOfWeek(weekNumber)).Sum
    End Function

    Public Function SalesAmountOfWeek(weekNumber As Integer) As Double
        Return (From p In Me Select p.SalesAmountOfWeek(weekNumber)).Sum
    End Function

Open in new window

but I still encounter the same problem to "Return" linve in above.
0
Naitik GamitSoftware DeveloperCommented:
which line occurred error?????
0
HuaMin ChenProblem resolverAuthor Commented:
these 2 errors
Error	22	Expression of type 'KongTaiToolbar.YearlySalesByShoesTypeMonth' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.	
Error	23	Expression of type 'KongTaiToolbar.YearlySalesByShoesTypeMonth' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.	

Open in new window

due to the above 2 "Return" lines
0
Naitik GamitSoftware DeveloperCommented:
try to use linq in another ways(use different syntax) and also try


 Return (From p In Me Select p.SalesAmountOfWeek(weekNumber)).Sum().AsQueryable();
0
HuaMin ChenProblem resolverAuthor Commented:
I put the line like

        Return (From p In Me Select p.SalesQtyOfWeek(weekNumber)).Sum().AsQueryable
...

Open in new window

But I still get this

Error	12	Expression of type 'KongTaiToolbar.YearlySalesByShoesTypeMonth' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.	

Open in new window

0
it_saigeDeveloperCommented:
You get the error because the class *YearlySalesByShoesTypeMonth* is not an enumerable type.

Your function states:
Return (From p In Me Select p.SalesQtyOfWeek(weekNumber)).Sum

Open in new window

Your usage of Me (this for C#) stipulates the class instance.  As the class does not implement an enumerated interface; e.g. - ICollection, IList, IDictionary, IEnumerable, etc. etc.; or inherit from an enumerated type; e.g. - Collection, List, Dictionary, Enumerable, etc. etc.; the class cannot be enumerated over.

To fix your issue I you need to either implement an enumerated interface, inherit from an enumerated type or provide access to the emumerated object you want to retrieve your data from.

To implement an enumerated interface you would do something like:
Public Class YearlySalesByShoesTypeMonth
	Implements IList<sometypehere>

Open in new window

To inherit from an enumerated type you would do something like:
Public Class YearlySalesByShoesTypeMonth
	Inherits List<sometypehere>

Open in new window

Understand that using the interface approach means that you have to Implement the methods and properties as defined by the interface.

Only at this point would your function work as is.

-saige-
0
it_saigeDeveloperCommented:
Proof of concept:
Module Module1
	ReadOnly pets As Cats = New Cats(From i In Enumerable.Range(0, 9) Select New Cat() With {.ID = i, .Name = String.Format("Whiskers{0}", i), .Lives = i + 1})

	Sub Main()
		Console.WriteLine(pets.CatsWithLivesRemaining(8))
		Console.ReadLine()
	End Sub
End Module

Class Cats
	Inherits List(Of Cat)

	Public Sub New()
		MyBase.New()
	End Sub

	Public Sub New(ByVal capacity As Integer)
		MyBase.New(capacity)
	End Sub

	Public Sub New(ByVal source As IEnumerable(Of Cat))
		MyBase.New(source)
	End Sub

	Public Function CatsWithLivesRemaining(ByVal lives As Integer) As Integer
		Return (From c As Cat In Me Where c.Lives = lives Select c).Count
	End Function
End Class

Class Cat
	Public Property ID() As Integer
	Public Property Name() As String
	Public Property Lives() As Integer

	Public Overrides Function Equals(ByVal obj As Object) As Boolean
		If obj Is Nothing OrElse Not obj.GetType().Equals(Me.GetType()) Then
			Return False
		End If

		Return Me.Equals(DirectCast(obj, Cat))
	End Function

	Public Overloads Function Equals(ByVal [cat] As Cat) As Boolean
		If Object.ReferenceEquals([cat], Nothing) Then
			Return False
		End If

		If [cat] Is Me Then
			Return True
		End If

		Return ID.Equals([cat].ID) AndAlso Name.Equals([cat].Name) AndAlso Lives.Equals([cat].Lives)
	End Function

	Public Overrides Function GetHashCode() As Integer
		Return ID.GetHashCode() Xor Name.GetHashCode() Xor Lives.GetHashCode()
	End Function

	Public Shared Operator =(ByVal lhs As Cat, ByVal rhs As Cat)
		Return Object.Equals(lhs, rhs)
	End Operator

	Public Shared Operator <>(ByVal lhs As Cat, ByVal rhs As Cat)
		Return Not lhs = rhs
	End Operator
End Class

Open in new window

Which produces the following output -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.