2017-04-02 27 views
0

我有簡單Azure Mobile Service其被連接到MySql Database天青移動服務得到錯誤 - 序列含有不匹配元件

Web.Config

<connectionStrings> 
    <add name="MS_TableConnectionString" connectionString="Server=11.11.111.111;User Id=test;Password=test;Database=testDB" providerName="MySql.Data.MySqlClient" /> 
    </connectionStrings> 

App_Start\WebApiConfig.cs

public static class WebApiConfig 
    { 
     public static void Register() 
     {   
      ConfigOptions options = new ConfigOptions(); 

      HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options)); 

      config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; 

     } 
    } 

Controllers\CommentController.cs

public class CommentController : TableController<wp_comments> 
    { 
     protected override void Initialize(HttpControllerContext controllerContext) 
     { 
      base.Initialize(controllerContext); 
      MobileServiceContext context = new MobileServiceContext(); 
      DomainManager = new EntityDomainManager<wp_comments>(context, Request, Services); 
     } 

     // GET tables/Comment 
     public IQueryable<wp_comments> GetAllComment() 
     {    
      return Query(); // Getting Exception Here 
     } 

DataObjects\wp_comments.cs

public class wp_comments : EntityData 
    { 
     public int comment_ID { get; set; } 
     public int comment_post_ID { get; set; } 

     [Column("comment_author", TypeName = "NVARCHAR(MAX)")] 
     public string comment_author { get; set; } 

     [Column("comment_author_email", TypeName = "NVARCHAR(MAX)")] 
     public string comment_author_email { get; set; } 

     [Column("comment_author_url", TypeName = "NVARCHAR(MAX)")] 
     public string comment_author_url { get; set; } 

     [Column("comment_author_IP", TypeName = "NVARCHAR(MAX)")] 
     public string comment_author_IP { get; set; } 
     public DateTime comment_date { get; set; } 
     public DateTime comment_date_gmt { get; set; } 

     [Column("comment_author_IP", TypeName = "NVARCHAR(MAX)")] 
     public string comment_content { get; set; } 
     public int comment_karma { get; set; } 

     [Column("comment_approved", TypeName = "NVARCHAR(MAX)")] 
     public string comment_approved { get; set; } 

     [Column("comment_agent", TypeName = "NVARCHAR(MAX)")] 
     public string comment_agent { get; set; } 

     [Column("comment_type", TypeName = "NVARCHAR(MAX)")] 
     public string comment_type { get; set; } 
     public int comment_parent { get; set; } 
     public int user_id { get; set; } 
    } 

Models\MobileServiceContext.cs

public class MobileServiceContext : DbContext 
    { 

     private const string connectionStringName = "Name=MS_TableConnectionString"; 

     public MobileServiceContext() : base(connectionStringName) 
     { 
     } 

     public DbSet<wp_comments> Comments { get; set; } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      string schema = ServiceSettingsDictionary.GetSchemaName(); 
      if (!string.IsNullOrEmpty(schema)) 
      { 
       modelBuilder.HasDefaultSchema(schema); 
      } 

      //modelBuilder.Conventions.Add(
      // new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>(
      //  "ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString())); 
     } 
    } 

回答

1

請與模型檢查,您已經定義了同一個屬性 「comment_author_IP」。請修改它,然後查看您的代碼是否有效。

[Column("comment_author_IP", TypeName = "NVARCHAR(MAX)")] 
    public string comment_author_IP { get; set; } 
    public DateTime comment_date { get; set; } 
    public DateTime comment_date_gmt { get; set; } 

    [Column("comment_author_IP", TypeName = "NVARCHAR(MAX)")] 
    public string comment_content { get; set; } 
+0

感謝我糾正了還是同樣的錯誤 - 後來我又刪除了所有'[專欄]'屬性和它的工作原理:) – Neo