ObjectDataSource error

S

shapper

Hello,

I am creating a ListView with an ObjectDataSource and Linq. However I
am getting an error:

ObjectDataSource 'odsTags' could not find a non-generic method
'GetTags' that has no parameters.

The GetTags function is there! Here is my code:

Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Init

With lvTags
.DataKeyNames = New String() {"TagID"}
.DataSourceID = "odsTags"
.ID = "lvTags"
.InsertItemPosition = InsertItemPosition.FirstItem
.EditItemTemplate = New
TagsTemplate(TemplateType.EditItemTemplate)
.InsertItemTemplate = New
TagsTemplate(TemplateType.InsertItemTemplate)
.ItemTemplate = New TagsTemplate(TemplateType.ItemTemplate)
.LayoutTemplate = New
TagsTemplate(TemplateType.LayoutTemplate)
End With

End Sub

Private Sub odsTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles odsTags.Init
With odsTags
.ID = "odsTags"
.SelectMethod = "GetTags"
.TypeName = "Tag"
End With
End Sub

Public Shared Function GetTags() As ICollection

Dim database As New CodeDataContext
Dim tags = From t In database.Tags _
Select t.TagID, _
t.Text, _
Active = t.FilesTags.Any Or
t.ArticlesTags.Any
Return tags

End Function

What am I doing wrong?

I suspect it might be because of

..TypeName = "Tag"

But if I don't use this I get the following error:

A type must be specified in the TypeName property of ObjectDataSource
'odsTags'.

Thank You,

Miguel
 
S

shapper

Hello,

I am creating a ListView with an ObjectDataSource and Linq. However I
am getting an error:

ObjectDataSource 'odsTags' could not find a non-generic method
'GetTags' that has no parameters.

The GetTags function is there! Here is my code:

Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Init

With lvTags
.DataKeyNames = New String() {"TagID"}
.DataSourceID = "odsTags"
.ID = "lvTags"
.InsertItemPosition = InsertItemPosition.FirstItem
.EditItemTemplate = New
TagsTemplate(TemplateType.EditItemTemplate)
.InsertItemTemplate = New
TagsTemplate(TemplateType.InsertItemTemplate)
.ItemTemplate = New TagsTemplate(TemplateType.ItemTemplate)
.LayoutTemplate = New
TagsTemplate(TemplateType.LayoutTemplate)
End With

End Sub

Private Sub odsTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles odsTags.Init
With odsTags
.ID = "odsTags"
.SelectMethod = "GetTags"
.TypeName = "Tag"
End With
End Sub

Public Shared Function GetTags() As ICollection

Dim database As New CodeDataContext
Dim tags = From t In database.Tags _
Select t.TagID, _
t.Text, _
Active = t.FilesTags.Any Or
t.ArticlesTags.Any
Return tags

End Function

What am I doing wrong?

I suspect it might be because of

.TypeName = "Tag"

But if I don't use this I get the following error:

A type must be specified in the TypeName property of ObjectDataSource
'odsTags'.

Thank You,

Miguel

Hello,

It seems there are almost no real documentation online on using a
ObjectDataSource with Linq!

This is the only one I found that helped me:

http://msdn2.microsoft.com/en-us/library/bb907622.aspx

I am quoting one part of it:

"You can use the ObjectDataSource control with a LINQ to SQL class.
To do so, you set the TypeName property to the name of the data-
context class."

This was what solved my problem.

But the following is still a problem:

"You also set the SelectMethod, UpdateMethod, InsertMethod, and
DeleteMethod methods to the methods in the data-context class that
perform the corresponding operations."

What methods in the data-context?

I can't find it. I generated using the Linq to SQL classes. Any idea?

And finally this one beats me:

"When you use deferred query execution with the ObjectDataSource
control, you must create an event handler for the ObjectDisposing
event in order to cancel disposing of the data-context class. This
step is necessary because LINQ to SQL supports deferred execution,
whereas the ObjectDataSource control tries to dispose the data context
after the Select operation."

Any idea?

Thanks,

Miguel
 
S

shapper

Hello,

It seems there are almost no real documentation online on using a
ObjectDataSource with Linq!

This is the only one I found that helped me:

http://msdn2.microsoft.com/en-us/library/bb907622.aspx

I am quoting one part of it:

"You can use the ObjectDataSource control with a LINQ to SQL class.
To do so, you set the TypeName property to the name of the data-
context class."

This was what solved my problem.

But the following is still a problem:

"You also set the SelectMethod, UpdateMethod, InsertMethod, and
DeleteMethod methods to the methods in the data-context class that
perform the corresponding operations."

What methods in the data-context?

I can't find it. I generated using the Linq to SQL classes. Any idea?

And finally this one beats me:

"When you use deferred query execution with the ObjectDataSource
control, you must create an event handler for the ObjectDisposing
event in order to cancel disposing of the data-context class. This
step is necessary because LINQ to SQL supports deferred execution,
whereas the ObjectDataSource control tries to dispose the data context
after the Select operation."

Any idea?

Thanks,

Miguel

Correction,

I wasn't able to solve my problem.

Do I need to place the Select, Insert, ... Methods inside my
DataContext?

Thanks,

Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top