Breeze中EntityManager的服务名称是什么?

时间:2013-05-20 21:22:07

标签: javascript asp.net-mvc breeze

我只是不明白我必须将其设置为EntityManager的服务名称。

我有两个控制器:一个ApiController和一个'普通'控制器:

API控制器:

[BreezeController]
public class TournamentApiController : ApiController
{
    private EFContextProvider<TournamentContext> _contextProvider;

    public TournamentApiController()
    {
        _contextProvider = new EFContextProvider<TournamentContext>();
    }

    [HttpGet]
    public string Metadata()
    {
        return _contextProvider.Metadata();
    }

    [HttpGet]
    public IQueryable<Tournament> Tournaments()
    {
        return _contextProvider.Context.Tournaments;
    }

    [HttpGet]
    public IQueryable<Team> Teams()
    {
        return _contextProvider.Context.Teams;
    }
}

'正常'控制器:

public class TournamentController : Controller
{
    public ActionResult Index()
    {
        return PartialView();
    }

    public ActionResult Details()
    {
        return PartialView();
    }
}

在我的DataSrvice.js文件中:

app.dataservice = (function (breeze) {

breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);

var serviceName = '/TournamentApi'; // What exactly do I need to set here? 

// *** Cross origin service example  ***
//var serviceName = 'http://todo.breezejs.com/breeze/todos'; // controller in different origin

var manager = new breeze.EntityManager(serviceName);
// manager.enableSaveQueuing(true);

var dataservice = {
    getAllTournaments: getAllTournaments,
};
return dataservice;

/*** implementation details ***/
function getAllTournaments() {
    var query = breeze.EntityQuery
            .from("Tournament");

    return manager.executeQuery(query);
}
})(breeze);

有人可以解释一下服务名称的含义,以及我应该用作服务名称的内容吗?

1 个答案:

答案 0 :(得分:0)

serviceName标识服务端点,即Web API控制器的路由。这将是&#34; root&#34;您用来与服务器通信的URL的名称。因此,如果实际端点要查询“团队”。和#&#39;锦标赛&#39;是

 http://foo/bar/tournamentApp/teams ...
 http://foo/bar/tournamentApp/tournaments ...

那么您的服务名称将是

"foo/bar/tournamentApp"