私はAzure Mobile Appを作成し、生成されたバックエンドとモバイルアプリをダウンロードしました。私がそれを始めると、db内の2つのtodo項目が正常に取得されます。ただし、以下のようにユーザーモデルを追加するとすぐに、モバイルアプリでToDo項目が取得されなくなります。私は何が紛争を引き起こしているのか分かりません。私はユーザモデルに&の参照を削除した場合、私はDBcontextからこの行をコメントアウトすると、それが再び動作する C#Azureモバイルアプリ - 新しいモデルを追加できない
- 、私は再びモバイルアプリのTODOアイテムを取得することができます。
//public DbSet<User> Users { get; set; }
スタートアップ:
public partial class Startup { public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Map routes by attribute config.MapHttpAttributeRoutes(); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new AuthApp231Initializer()); // To prevent Entity Framework from modifying your database schema, use a null database initializer // Database.SetInitializer<AuthApp231Context>(null); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { // This middleware is intended to be used locally for debugging. By default, HostName will // only have a value when running in an App Service application. app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } app.UseWebApi(config); } } public class AuthApp231Initializer : CreateDatabaseIfNotExists<AuthApp231Context> { protected override void Seed(AuthApp231Context context) { List<TodoItem> todoItems = new List<TodoItem> { new TodoItem { Id = Guid.NewGuid().ToString(), Text = "First item", Complete = false }, new TodoItem { Id = Guid.NewGuid().ToString(), Text = "Second item", Complete = false }, }; foreach (TodoItem todoItem in todoItems) { context.Set<TodoItem>().Add(todoItem); } /*List<User> users = new List<User> { new User { Id = Guid.NewGuid().ToString(), Username = "adrian", Password = "supersecret" } }; foreach (User user in users) { context.Set<User>().Add(user); }*/ base.Seed(context); } }
ダットaObjects:
public class User :EntityData { public string Username { get; set; } public string Password { get; set; } }
コンテキスト:
public class AuthApp231Context : DbContext { // You can add custom code to this file. Changes will not be overwritten. // // If you want Entity Framework to alter your database // automatically whenever you change your model schema, please use data migrations. // For more information refer to the documentation: // http://msdn.microsoft.com/en-us/data/jj591621.aspx private const string connectionStringName = "Name=MS_TableConnectionString"; public AuthApp231Context() : base(connectionStringName) { } public DbSet<TodoItem> TodoItems { get; set; } public DbSet<User> Users { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Add( new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>( "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString())); } }
感謝を。私は実際にあなたの本(第2章)に従って認証を実装しました。私はすべてのステップを踏んだが、それを動作させることができなかった。ユーザーモデル用。 DataAnnotationsはもはや有効ではありません。そのため、私はユーザーにEntityDataを使用しました。 –
EntityDataは、Entity Frameworkを使用するITableDataの単なる実装です。 DataAnnotationsはEntity Frameworkから提供されます。エンティティフレームワークの.NETCore版にアップグレードした場合(最も確実に行うべきではない)、これが可能性の高い結果です。 –