I use Entity Framework 6.0.0.0
, and approach is Database First
.
I have three tables Client
, Account
, Doc
. One Client
has many Docs
and Accounts
. The relationship is one to many. Client
table:
public partial class Client
{
public Client()
{
this.Account = new HashSet<Account>();
this.Doc = new HashSet<Doc>();
}
public int ClientId { get; set; }
public string Name { get; set; }
public virtual ICollection<Account> Account { get; set; }
public virtual ICollection<Doc> Doc { get; set; }
}
AngularJs
code snippet to take data from WebApi
:
angular.module("app", []).controller("searchController", function ($scope, $http) {
//Used to get and display the data
$http.get('/api/Search/').success(function (data) {
debugger;
$scope.searchs = data;
$scope.loading = false;
})
.error(function () {
debugger;
$scope.error = "An Error has occured while loading posts!";
$scope.loading = false;
});
}
Method Get
of Web API
to take data(it returns NOTHING. There is no clients):
[HttpGet]
public IEnumerable<Client> Get()
{
private ClientDBEntities db = new ClientDBEntities();
retutn db.Client.AsEnumerable();// it returns NOTHING. There is no clients
}
However, $http.get('/api/Search/').success(function (data)
called, if I change this method to return IEnumerable<string>
:
[HttpGet]
public IEnumerable<Client> Get()
{
List<string> list = new List<string>(){"1", "2", "3"};
return list;
}
My question is why db.Client.AsEnumerable()
returns nothing? I've tried to change this code to:
retutn db.Client.ToList();// it returns all necessary data
However, AngularJS method is calling $http.get('/api/Search/').error(...)
Any help would be greatly appreciated.