这篇文章 ( https://stackoverflow.com/a/14486260/894358 ) 表明 Breeze 确实支持继承,但我的微风管理器无法理解从 API 返回的元数据。服务器将从其他操作方法返回元数据和 JSON 结果,但是当管理器尝试解释元数据时,它会抛出错误:“无法读取未定义的 propertyRef”。
这是我非常简单的实现(Code First Migrations 生成数据库):
namespace VerySimpleVehicleModel.Models
{
public abstract class Vehicle
{
public int Id { get; set; }
public int Speed { get; set; }
}
public class Bus: Vehicle
{
public int Capacity { get; set; }
}
public class Car : Vehicle
{
public string Color { get; set; }
}
public class VehicleContext : DbContext
{
public DbSet<Car> Cars { get; set; }
public DbSet<Bus> Buses { get; set; }
public DbSet<Vehicle> Vehicles { get; set; }
}
}
namespace VerySimpleVehicleModel.Controllers
{
[BreezeController]
public class BreezeController : ApiController
{
readonly EFContextProvider<VehicleContext> _contextProvider = new EFContextProvider<VehicleContext>();
[HttpGet]
public string Metadata()
{
return _contextProvider.Metadata();
}
[HttpGet]
public IQueryable<Car> Cars()
{
return _contextProvider.Context.Cars;
}
}
}
这是从 Metadata 操作方法返回的元数据:
"{
\"schema\":
{
\"namespace\":\"VerySimpleVehicleModel.Models\",
\"alias\":\"Self\",
\"d4p1:UseStrongSpatialTypes\":\"false\",
\"xmlns:d4p1\":\"http://schemas.microsoft.com/ado/2009/02/edm/annotation\",
\"xmlns\":\"http://schemas.microsoft.com/ado/2009/11/edm\",
\"cSpaceOSpaceMapping\":\"
[
[
\\\"VerySimpleVehicleModel.Models.Vehicle\\\",
\\\"VerySimpleVehicleModel.Models.Vehicle\\\"
],
[
\\\"VerySimpleVehicleModel.Models.Car\\\",
\\\"VerySimpleVehicleModel.Models.Car\\\"
],
[
\\\"VerySimpleVehicleModel.Models.Bus\\\",
\\\"VerySimpleVehicleModel.Models.Bus\\\"
]
]
\",\"entityType\":
[
{
\"name\":\"Car\",
\"baseType\":\"Self.Vehicle\",
\"property\":
{
\"name\":\"Color\",
\"type\":\"Edm.String\",
\"fixedLength\":\"false\",\"maxLength\":\"Max\",
\"unicode\":\"true\",\"nullable\":\"true\"
}
},
{
\"name\":\"Bus\",
\"baseType\":\"Self.Vehicle\",
\"property\":{\"name\":\"Capacity\",
\"type\":\"Edm.Int32\",\"nullable\":\"false\"}
},
{
\"name\":\"Vehicle\",
\"abstract\":\"true\",
\"key\":{\"propertyRef\":{\"name\":\"Id\"}},
\"property\":
[
{\"name\":\"Id\",\"type\":\"Edm.Int32\",\"nullable\":\"false\",\"d4p1:StoreGeneratedPattern\":\"Identity\"},
{\"name\":\"Speed\",\"type\":\"Edm.Int32\",\"nullable\":\"false\"}
]
}
]
,\"entityContainer\":
{
\"name\":\"VehicleContext\",
\"entitySet\":
{
\"name\":\"Vehicles\",
\"entityType\":\"Self.Vehicle\"
}
}
}
}"