我正在使用Breeze.WebApi2.EF6我有一个简单的微风控制器和一个简单的查询但是当我执行一个选择我得到的所有数据不仅仅是我选择的那些,你能帮我吗? / p>
微风控制器
[BreezeController]
public class BreezeController : ApiController
{
readonly EFContextProvider<CodeCamperDbContext> _contextProvider =
new EFContextProvider<CodeCamperDbContext>();
[HttpGet]
[Route("breeze/Metadata")]
public string GetMetadata()
{
return _contextProvider.Metadata();
}
[HttpGet]
[Route("breeze/GetLookups")]
public object Lookups()
{
var rooms = _contextProvider.Context.Rooms;
var tracks = _contextProvider.Context.Tracks;
var timeSlots = _contextProvider.Context.TimeSlots;
return new { rooms, tracks, timeSlots };
}
[HttpGet]
[Route("breeze/GetSessions")]
public IEnumerable<Session> Sessions()
{
var result = _contextProvider.Context.Sessions;
return result;
}
[HttpGet]
[Route("breeze/GetPersons")]
public IEnumerable<Person> Persons()
{
var result = _contextProvider.Context.Persons;
return result;
}
[HttpGet]
[Route("breeze/GetSpeakers")]
public IEnumerable<Person> Speakers()
{
var result = _contextProvider.Context.Persons
.Where(p => p.SpeakerSessions.Any());
return result;
}
}
datacontext.js
var getSessionsPartials = function (sessionsObservable) {
// Create breeze query
var query = EntityQuery.from('GetSessions')
.select('id, title, code')
.orderBy('timeSlotId, level, speaker.firstName');
// Execute breeze query
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
// Handle the success callback
function querySucceeded(data) {
if (sessionsObservable) {
sessionsObservable(data.results);
}
log('Retrieved [Sessions] from remote data source', data, true);
}
};
我应该得到(id,title,code),但我也得到所有其他数据。
答案 0 :(得分:3)
代替IEnumerable
,使用IQueryable
...
public IQueryable<Session> Sessions()
...等
这使得在方法调用之后附加的任何表达式都可以转换为SQL。当您公开IEnumerable
时,与原始查询提供程序的连接将被删除。