Home > English > The type DomainContext does not expose a method called ‘GetCustomer2Query’

The type DomainContext does not expose a method called ‘GetCustomer2Query’

This error message was a common one that I was receiving when I switched from Linq2Sql to Linq2Entities. The reason behind this was that Linq2Sql pluralized my data model and so I was trying to look for the same corresponding query for Linq2Entities exposed by WCF RIA Services.

Here is the Xaml that causes the problem. It is valid Xaml but you will get a runtime error:

<UserControl
    x:Class="SampleView"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:riaCtls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
    >
    <Grid >
        <riaCtls:DomainDataSource x:Name="_dds"
            QueryName="GetCustomer2Query"
            AutoLoad="False" PageSize="25" LoadSize="100"
            DomainContext="{Binding DomainContext, Mode=TwoWay}" />

        ...

    </Grid>
</UserControl>

At runtime, you will get the following error:

The type DomainContext does not expose a method called ‘GetCustomer2Query’

This message is simple to fix, all I did was correct the query as you can see below:

<UserControl
    x:Class="SampleView"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:riaCtls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
    >
    <Grid >
        <riaCtls:DomainDataSource x:Name="_dds"
            QueryName="GetCustomerQuery"
            AutoLoad="False" PageSize="25" LoadSize="100"
            DomainContext="{Binding DomainContext, Mode=TwoWay}" />

        ...

    </Grid>
</UserControl>

The subtle difference is in the actual name of the query. This could be a blatant error or something as subtle as pluralization.

As a side note, the word “Query” can be ommitted. WCF RIA Services will honor the query name regardless.

Hope this helps…

Advertisements
  1. August 31, 2011 at 12:59 pm

    I liked your article is an interesting technology
    thanks to google I found you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: