小编hyp*_*erN的帖子

Azure恢复已删除的数据库

我不小心删除了链接到数据库的Azure网站,现在我的数据库已经不见了.

有什么办法可以从数据库中恢复数据吗?

azure azure-sql-database

6
推荐指数
2
解决办法
3644
查看次数

无法加载文件或程序集FSharp.Core,Version = 4.0.0.0 Azure Web Role

我已经在我的项目(http://mcapinet.codeplex.com/)中为Mailchimp添加了NuGet包,这个包依赖于FSharp.Core,所以当我在本地机器上安装包时,它已被添加为参考(和一切正常,但是当我在Azure上发布我的Cloud Service时(注意:我正在使用Visual Studio Online进行持续部署),当我访问网站时出现此错误:

Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

并且FSharp.Core的属性"Copy local"设置为True.

我怎么解决这个问题?

编辑

在我的部署期间,我可以看到此警告:

The project 'Interface.Web' is dependent on the following assembly: C:\a\src\TFS\packages\FSharp.Core.4.0.0\lib\FSharp.Core.dll. This assembly is not in the package. To make sure that the role starts, add this assembly as a reference to the project and set the Copy Local property to true
Run Code Online (Sandbox Code Playgroud)

c# azure

6
推荐指数
1
解决办法
3019
查看次数

导航属性"SenderId"不是"对话"类型的声明属性

当我尝试做Update-Database时,我收到此错误:

导航属性"SenderId"不是"对话"类型的声明属性.验证它是否未从模型中明确排除,并且它是有效的导航属性.

编辑

我认为问题在于对话和用户之间的映射关系,因为对话和用户与两个一对多关系连接,即对话有两个指向用户的外键

以下是用户和对话的连接方式:

用户:

public class User
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid UserId { get; set; }

    public virtual ICollection<Conversation> ConversationSenders { get; set; }
    public virtual ICollection<Conversation> ConversationRecievers { get; set; }
Run Code Online (Sandbox Code Playgroud)

会话:

public class Conversation
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    public Guid ConversationId { get; set; }

    [ForeignKey("SenderId")]
    public Guid SenderId { get; set; }

    [ForeignKey("RecieverId")]
    public Guid RecieverId { get; set; }

    [InverseProperty("ConversationSenders")]
    public virtual User Sender { get; set; }

    [InverseProperty("ConversationRecievers")] …
Run Code Online (Sandbox Code Playgroud)

.net entity-framework database-migration ef-code-first ef-migrations

5
推荐指数
1
解决办法
1万
查看次数

mvc 4 MultiSelect列表和EF多对多

我有这些实体(它们之间存在多对多的连接):

public class Post
{     
    public Guid PostId { get; set; }     
    public string Name { get; set; }       
    public virtual ICollection<Tag> Tags { get; set; }
}

  public class Tag
{
    public int TagId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Post> Posts { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我希望用户在创建Post时,从MultiSelectList和MultiSelectList中选择数据,将该数据传递给Post.Tags.我怎样才能做到这一点 ?

asp.net-mvc entity-framework

5
推荐指数
1
解决办法
8740
查看次数

ASP.net MVC + ASP.net Identity Seeding角色和用户

在Migrations Configuration类中,有Seed方法,它看起来像:

protected override void Seed(DatabaseContext context)
        {
           var  roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
           var  userManager = new UserManager<User>(new UserStore<User>(context)); 

            if (!roleManager.RoleExists("Administrator"))
            {
                roleManager.Create(new IdentityRole("Administrator"));
            }

            var user = new User {UserName = "someUserName"};


            if (userManager.FindByName("someUserName") == null)
            {
                var result = userManager.Create(user, "password");

                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, "Administrator");
                }    

            }
            }
Run Code Online (Sandbox Code Playgroud)

然后在PM控制台中我运行update-database,它成功地播种了数据库,在表AspNetUserRoles中我可以看到用户someUserName和Administrator角色已连接.

但是,当我将属性[Authorize(Roles = "Administrator")]放在控制器上方时,我已被重定向到登录页面,好像我的用户不在那个角色中,所以我在控制器中添加了一行:

var x = _userManager.IsInRole(_userManager.FindByName("someUserName").Id, "Administrator");
Run Code Online (Sandbox Code Playgroud)

而x是假的.为什么会这样?我该如何解决?如果这不是种子数据库的正确方法,那是什么?

asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity

5
推荐指数
1
解决办法
7562
查看次数

剑道+角度图表数据

我正在尝试使用角度的剑道图表,我有显示数据的问题,这是我的代码:

HTML:

<div  kendo-chart="rchart" data-k-options="chartOptions" data-role="chart" class="k-chart" style="position: relative;"></div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

resultService.getResult().then(function (resultResponse) {
         $scope.data = resultResponse.data;
         $scope.oldReps = _.pluck($scope.data.TreningScores.Item1, 'Item2');
         $scope.newReps = _.pluck($scope.data.TreningScores.Item2, 'Item2');
         $scope.categories = _.pluck($scope.data.TreningScores.Item1, 'Item1');
     });


$scope.chartOptions = {

         legend: {
             position: "bottom"
         },
         seriesDefaults: {
             type: "column"
         },
         series: [{
             name: "Total Visits",
             data: $scope.oldReps
         }, {
             name: "Unique visitors",
             data: $scope.newReps
         }],
         valueAxis: {
             line: {
                 visible: false
             }
         },

         tooltip: {
             visible: true,
             format: "{0}"
         }
     };
Run Code Online (Sandbox Code Playgroud)

问题是从服务器获取数据后图表没有更新,我尝试刷新这样的图表(但没有运气):

$scope.chart = {        
        refreshChart : function() …
Run Code Online (Sandbox Code Playgroud)

javascript kendo-ui angularjs kendo-dataviz

5
推荐指数
1
解决办法
8397
查看次数

脚手架时Web api Odata错误

我试图为这个实体搭建Odata控制器:

        #region Attributes

        public Guid TreningId { get; set; }
        public DateTime DateTimeWhenTreningCreated { get; set; }

        #endregion

        #region Navigational properties

        public string UserId { get; set; }
        public User User { get; set; }

        public int RoutineId { get; set; }
        public Routine Routine { get; set; }


        #endregion
Run Code Online (Sandbox Code Playgroud)

脚手架很好,我也使用ASP.net Identity,但我的用户类和数据库上下文在另一个项目中定义如下:

public class User : IdentityUser
    {
        public String Something { get; set; }

    }

And database context looks like this:

     public class DatabaseContext : IdentityDbContext<User>
        {
            public MadBarzDatabaseContext() …
Run Code Online (Sandbox Code Playgroud)

entity-framework odata asp.net-web-api

5
推荐指数
1
解决办法
1082
查看次数

实体框架更改Id类型

我已经将Int属性的类型从Int更改为Guid,没有其他实体引用Id并且我从数据库中手动删除了该实体的所有记录,我生成的迁移类如下所示:

public override void Up()
{
    AlterColumn("dbo.RoutineExercises", "RoutineExerciseId", c => c.Guid(nullable: false));
}

public override void Down()
{
    AlterColumn("dbo.RoutineExercises", "RoutineExerciseId", c => c.Int(nullable: false, identity: true));
}
Run Code Online (Sandbox Code Playgroud)

当我运行update-database命令时,我收到此错误:

对象'PK_dbo.RoutineExercises'依赖于列'RoutineExerciseId'.ALTER TABLE ALTER COLUMN RoutineExerciseId失败,因为一个或多个对象访问此列.

我的FluentAPI配置如下所示:

 modelBuilder.Entity<RoutineExercise>().HasKey(r => r.RoutineExerciseId);
 modelBuilder.Entity<RoutineExercise>()
                .HasRequired(r => r.Exercise)
                .WithMany()
                .HasForeignKey(r => r.ExerciseId)
                .WillCascadeOnDelete(true);

            modelBuilder.Entity<RoutineExercise>()
                .HasRequired(r => r.Routine)
                .WithMany()
                .HasForeignKey(r => r.RoutineId)
                .WillCascadeOnDelete(true);
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题而不丢弃整个数据库?

c# sql sql-server entity-framework

5
推荐指数
1
解决办法
1214
查看次数

实体框架更改主键类型

我正在使用EF 6.0 Code First,我有这个实体:

 public class TrainingRespect
 {
    [Key]
    public int RespectId { get; set; }

    public DateTime? DateWhenRespected { get; set; }

    #region

    public string UserId { get; set; }
    public User User { get; set; }

    public Guid TrainingId { get; set; }
    public Trening Training { get; set; }

    #endregion
 }
Run Code Online (Sandbox Code Playgroud)

我想将它的主键(RespectId)从int更改为GUID/string/long.

这样做最简单的方法是什么?我可以只改变类型,EF迁移会处理所有事情,还是应该以其他方式完成?

c# entity-framework entity-framework-6

5
推荐指数
1
解决办法
2421
查看次数

实体框架 AutoDetectChangesEnabled = false 和 .Find

最近我在 EF 中发现了 AutoDetectChangesEnabled 选项,并且在官方文档中指出手动处理 AutoDetectChangesEnabled 可能会导致“微妙的错误”。

据我所知,将更改的实体保存到数据库时可能会出错,所以我的问题是:这段代码是否安全(默认情况下,实体框架在调用 Find 时自动执行检测更改):

using (var context = new DbContext())
{
    context.Configuration.AutoDetectChangesEnabled = false;
    var user = context.users.Find(id);
    context.Configuration.AutoDetectChangesEnabled = true;

    return user;
}
Run Code Online (Sandbox Code Playgroud)

所以,正如您所看到的,我没有对我的实体进行任何更改,只是返回它们,如果 AutoDetectChangesEnabled 设置为 false,Find 仍会先点击 Cache 然后再点击数据库?

c# entity-framework

5
推荐指数
1
解决办法
7579
查看次数