使用实体框架在列表框中显示项目

时间:2014-11-08 14:14:46

标签: c# database entity-framework webmethod service-reference

我正在尝试将我的Entity框架数据库中的项目显示到列表框中。我有两个不同的项目。首先是Empty Web app,第二个是Windows Forms(客户端)。

当我进入我的WF应用程序菜单时,我需要用户自动显示和刷新。

这是我的代码:

用户类

public class User
{
    public int UserID { get; set; }

    public string Name { get; set; }

    public string LastName { get; set; }

    public int Age { get; set; }

    public string Club { get; set; }

    public int Price { get; set; }

    public virtual List<Club> Clubs { get; set; }
}

WEB服务

[WebMethod]
    public List<Users> displayUsers()
    {
       using (var db = new Database())
       {
           return db.userList.ToList();
       }
    }

WINDOWS FORMS CODE

private void osveziPodakte()
    {
        ServiceReference1.mojWebServiceSoapClient client = new    ServiceReference1.mojWebServiceSoapClient();
        listBox1.Items.Add(client.displayUsers());
    }

当我运行程序时,数据库中的用户不会显示在列表框中。你能帮我解决一下代码吗?

非常感谢!

我运行程序时也会遇到此异常。

  

类型'System.ServiceModel.FaultException'的未处理异常   发生在mscorlib.dll

     

其他信息:System.Web.Services.Protocols.SoapException:   服务器无法处理请求。 ---&GT;   System.InvalidOperationException:生成错误时出错   XML文档。

0 个答案:

没有答案
相关问题