gpt4 book ai didi

c# - Azure 移动服务出现错误 - 序列不包含匹配元素

转载 作者:行者123 更新时间:2023-11-29 10:54:55 26 4
gpt4 key购买 nike

我有简单的Azure移动服务,它连接到MySql数据库

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; }
}

模型\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()));
}
}

最佳答案

请检查您的模型,您已定义相同的属性“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; }

关于c# - Azure 移动服务出现错误 - 序列不包含匹配元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43167617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com