我试图按照示例代码
尽我所能。
WebApiConfig:
config.Routes.MapODataRoute(
"AppAccountOData",
"odata",
GetModel()
);
...
API 路由
...
public static IEdmModel GetModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<User>("Users");
builder.EntitySet<EventLog>("EventLogs");
builder.EntitySet<Server>("Servers");
builder.EntitySet<Database>("Databass");
builder.EntitySet<Command>("Commands");
builder.EntitySet<Connection>("Conenctions");
builder.EntitySet<Query>("Queries");
builder.EntitySet<DirectoryGroup>("DirectoryGroups");
builder.EntitySet<ServiceAccount>("ServiceAccounts");
builder.EntitySet<EmailLog>("EmailLogs");
builder.EntitySet<EmailTemplate>("EmailTemplates");
builder.EntitySet<EventLog>("EventLogs");
builder.EntitySet<EventLogLevel>("EventLogLevels");
builder.EntitySet<EventLogSource>("EventLogSources");
builder.EntitySet<ApplicationServer>("ApplicationServers");
builder.EntitySet<ApplicationOnboardings_Old>("ApplicationOnboardings_Olds");
builder.EntitySet<ApplicationContact>("ApplicationContacts");
builder.EntitySet<ApplicationCategory>("ApplicationCategories");
builder.EntitySet<ApplicationOnboardingStatusType>("ApplicationOnboardingStatusTypes");
builder.EntitySet<ApplicationOnboarding>("ApplicationOnboardings");
builder.EntitySet<Application>("Applications");
builder.EntitySet<AppAccount>("AppAccounts");
builder.EntitySet<vAppAccountUser>("vAppAccountUsers");
builder.EntitySet<vUnmatchedAppAccount>("vUnmatchedAppAccounts");
builder.EntitySet<vTerminatedUser>("vTerminatedUsers");
builder.EntitySet<SvcAccount>("SvcAccounts");
builder.EntitySet<AppAccountClass>("AppAccountClasses");
var serviceAccounts = builder.Entity<AppAccount>().Collection.Action("Service");
serviceAccounts.ReturnsCollectionFromEntitySet<AppAccount>("AppAccounts");
return builder.GetEdmModel();
}
控制器中的功能很简单:
[HttpGet]
public ICollection<AppAccount> Service(ODataQueryOptions opts)
{
var results = opts.ApplyTo(db.AppAccounts.Where(aa => aa.AppAccountClass.Name == "Service")) as IQueryable<AppAccount>;
if (results != null) return results.ToList();
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
当我调用它时,我收到一个错误:
未实现。此服务不支持“~/entityset/action”形式的 OData 请求。