"user" classs auto generated by entity framework model first desinger.
public partial class user
{
public user()
{
this.distributorDevice = new HashSet<distributorDevice>();
this.managerDevice = new HashSet<managerDevice>();
this.logUserLogin = new HashSet<logUserLogin>();
this.logUserOperates = new HashSet<logUserOperates>();
this.clientApp = new HashSet<clientApp>();
}
public int Id { get; set; }
public string name { get; set; }
public byte[] password { get; set; }
public bool isActive { get; set; }
public System.DateTime RegisterTime { get; set; }
public int permissionId { get; set; }
public System.DateTime lastLoginTime { get; set; }
public virtual permission permission { get; set; }
public virtual ICollection<distributorDevice> distributorDevice { get; set; }
public virtual ICollection<managerDevice> managerDevice { get; set; }
public virtual ICollection<logUserLogin> logUserLogin { get; set; }
public virtual ICollection<logUserOperates> logUserOperates { get; set; }
public virtual ICollection<clientApp> clientApp { get; set; }
public virtual customerDevice customerDevice { get; set; }
}
If I wrote like this
public class UserController : ApiController
{
public IEnumerable<user> Get()
{
List<user> users = new List<user>();
return user;
}
}
When I visit "localhost:3700/api/user" in explorer,it works.
<ArrayOfuser xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/UpdateServer.Model"/>
If I wrote like this
public IEnumerable<user> Get()
{
using (var mydb = new ModelContainer())
{
return mydb.userSet.AsEnumerable();
}
}
When I visit "localhost:3700/api/user" in explorer, I get error message:
103 (net::ERR_CONNECTION_ABORTED)
Follow advices, I should use ToList() instead of asEnumerable, I change code like this
using (var mydb = new ModelContainer())
{
var users = mydb.userSet.ToList();
return users;
}
but still same error comes in explorer
103 (net::ERR_CONNECTION_ABORTED)
and I add a interrupt at
return users;
find that users already get the data from DB, but not correctly return to the client.
I do more test, I add an user with permission name "Admin", if I use code below, there is no user found, and it response to client correctly.
var users = mydb.userSet.Where(p=>p.permission.name == "Administrator").ToList();
return users;
if I write like this
var users = mydb.userSet.Where(p=>p.permission.name == "Admin").ToList();
return users;
it failed to return to client, give error
103 (net::ERR_CONNECTION_ABORTED)