对的,这是可能的。
像往常一样针对 EDMX 编写控制器。对我们来说,它翻译成这样的:
public class PersonalizationController : MultiTenantBreezeController<PersonalizationEntities>
其中 PersonalizationEntities 是一个 ObjectContext。
然后在服务器上,我们简单地定义 SaveChanges(不要介意覆盖,我们确实有一个基类)
[HttpPost]
public override SaveResult SaveChanges(JObject saveBundle)
{
// Deserialize the object that needs to get saved (ApplicationDefaults is my DTO)
var applicationDefaultsList = JsonConvert.DeserializeObject<List<ApplicationDefaults>>(saveBundle.SelectToken("entities").ToString());
// Do whatever logic you need to save the data
using (var repo = ServiceLocator.Current.Container.Resolve<IUserPreferenceRepository>())
{
// Your save logic here
}
// Construct the save result to inform the client that the server has completed the save operation
var keyMappings = new List<KeyMapping>();
return new SaveResult()
{
Entities = applicationDefaultsList.Cast<object>().ToList(),
Errors = null,
KeyMappings = keyMappings
};
}