开发者

wcf data service binding combobox

I have an application with silvelight and wcf data services. I want to populate comboBox with value of my column 'City'

Can someone give me the correct way to do this, because my function failed with System.InvalidOperationException !

public void GetCities(System.Windows.Controls.ComboBox cmbCity)
    {

        DataServiceQuery<String> userQuery = (DataServiceQuery<String>)proxy.CreateQuery<String>("GetCity");
                    try
        {
            userQuery.BeginExecute(
             (result) =>
             {
                 var userlist = new DataServiceCollection<string>(userQuery.EndExecute(result));

                 cmbCity.ItemsSource = userlist.ToList(); 

             }, null);

                       }
        catch (DataServiceQueryException ex)
        {
            throw ex;
        }
    }

In my WCF Data Service, :

 [WebGet]
public IQueryable<String> GetCity()
{
   return Usager.GetCity();
}

in my edmx project, I have this:

pub开发者_StackOverflow中文版lic static IQueryable<String> GetCity()
    {
        try
        {
            DataBaseEntities scv = new DataBaseEntities();
            return (from user in scv.Usager
                   select user.City).Distinct();


        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜