小编Sco*_*don的帖子

访问路径"/ etc/mono/registry"被拒绝

当我在我的Fedora 20工作站上使用xsp4(来自MonoDevelop或直接)运行我的ASP.NET MVC 4网站时,我遇到以下异常:

System.Web.HttpRuntime.FinishWithException (wr={Mono.WebServer.XSPWorkerRequest}, e={System.Web.HttpException:  ---> System.Web.HttpException: The pre-application start initialization method Start on type System.Web.WebPages.PreApplicationStartCode threw an exception with the following error message: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: An exception was thrown by the type initializer for <Module> ---> System.Security.SecurityException: No access to the given key ---> System.UnauthorizedAccessException: Access to the path "/etc/mono/registry" is denied.
at System.IO.Directory.CreateDirectoriesInternal (System.String …
Run Code Online (Sandbox Code Playgroud)

mono fedora xsp asp.net-mvc-4

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

EntityType'Category'没有定义键.定义此EntityType的键

开发基本的ASP.net MVC 4应用程序.它是一个简单的产品目录应用程序,我在其中有2个数据库表('Category'和'Products')

"产品"表中有"类别ID"("类别"表中的主键)的外键引用.

当我运行该应用程序时,我收到错误消息(如下所示).

System.Data.Entity.Edm.EdmEntityType: : EntityType 'Category' has no key defined. Define the key for this EntityType.

System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Category' is based on type 'Category' that has no keys defined
Run Code Online (Sandbox Code Playgroud)

这看起来像新手的常见错误,我确实检查了所有相关的解决方案'实体键''没有定义键.但仍然我的问题没有解决,请帮助我理解这个问题,这个问题的正确解决方案是什么.

以下是我的模型类

Category.cs

namespace ChemicalStore.Models
{
    public partial class Category
    {
        public int CatId { get; set; }
        public string CatName { get; set; }
        public string CatDescription { get; set; }
        public List<Product> Product { get; set; }
    }     
}
Run Code Online (Sandbox Code Playgroud)

Products.cs

namespace ChemicalStore.Models
{
    public class …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc entity-framework

35
推荐指数
4
解决办法
9万
查看次数

Nuget通过构建服务器恢复"无法找到版本"

我有一个VS解决方案,作为TeamCity Build的一部分,我们从私有NuGet提要(myget)和公共提要(nuget.org)恢复包.大多数软件包都可以恢复正常,但它依赖于下面的WebApi和Mono.Security.这都在Visual Studio中本地工作.

[restore] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\953bd084b49f7d88\DataFinch.Web.sln -Source https://www.myget.org/F/datafinch/auth/<hidden>/api/v2 -Source https://api.nuget.org/v3/index.json
[11:41:35][restore] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script473789219385667038.cmd
[11:41:35][restore] in directory: C:\TeamCity\buildAgent\work\953bd084b49f7d88
[11:41:35][restore] JetBrains TeamCity NuGet Runner 8.0.37059.9
[11:41:35][restore] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-2.8
[11:41:35][restore] Starting NuGet.exe 2.8.50926.602 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Client'.
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Core'.
[11:41:43][restore] Unable to find version '3.2.3.0' of package 'Mono.Security'.
[11:41:43][restore] Unable to find version '6.0.4' of package 'Newtonsoft.Json'.
[11:41:43][restore] Process exited with …
Run Code Online (Sandbox Code Playgroud)

c# teamcity nuget

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

如何使用Entity Framework自动过滤掉软删除的实体?

我正在使用Entity Framework Code First.我重写SaveChangesDbContext,让我做一个"软删除":

if (item.State == EntityState.Deleted && typeof(ISoftDelete).IsAssignableFrom(type))
{
    item.State = EntityState.Modified;
    item.Entity.GetType().GetMethod("Delete")
        .Invoke(item.Entity, null);

    continue;
}
Run Code Online (Sandbox Code Playgroud)

这很好,所以对象知道如何将自己标记为软删除(在这种情况下它只是设置IsDeletedtrue).

我的问题是我怎样才能使它在检索对象时忽略任何对象IsDeleted?所以,如果我说_db.Users.FirstOrDefault(UserId == id)如果该用户拥有IsDeleted == true它将忽略它.基本上我想过滤?

注意:我不想只是把&& IsDeleted == true 那就是为什么我用界面标记类,所以删除知道如何"正常工作",我想以某种方式修改检索,知道如何"正常工作"也基于那个界面存在.

.net c# entity-framework ef-code-first

34
推荐指数
4
解决办法
2万
查看次数

更改SQL Azure登录的默认数据库

我想更改登录的默认数据库,以支持可以访问SQL Azure但不允许轻松更改连接字符串的软件.看来SQL Azure默认使用master数据库.

我已经考虑过:

  • 存储过程.我找不到执行此操作的存储过程(sp_defaultdb据我所知,在SQL Azure中未实现)

  • 改变登录. ALTER LOGIN不允许DEFAULT_DATABASE选择.

  • SSMS.SSMS似乎不允许通过SQL Azure接口进行太多用户控制.

想法?

azure-sql-database

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

检查json类型列PostgreSQL中是否存在字段

你如何检查jsonPostgres中的某个字段是否有某个元素?

我尝试过json->>'attribute' is not null但不起作用.

postgresql json

33
推荐指数
2
解决办法
2万
查看次数

如何从另一个方法调用按钮单击事件

我怎么能用SubGraphButton_Click(object sender, RoutedEventArgs args)另一种方法打电话?

private void SubGraphButton_Click(object sender, RoutedEventArgs args)
{
}

private void ChildNode_Click(object sender, RoutedEventArgs args)
{
   // call SubGraphButton-Click().
}
Run Code Online (Sandbox Code Playgroud)

c#

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

如何使用Traits - Laravel 5.2

我是Traits的新手,但是我的函数中有很多重复的代码,我想使用Traits来减少代码的混乱.我Traits在我的Http目录中创建了一个名为Trait的目录BrandsTrait.php.它所做的只是呼吁所有品牌.但是当我尝试在我的产品控制器中调用BrandsTrait时,如下所示:

use App\Http\Traits\BrandsTrait;

class ProductsController extends Controller {

    use BrandsTrait;

    public function addProduct() {

        //$brands = Brand::all();

        $brands = $this->BrandsTrait();

        return view('admin.product.add', compact('brands'));
    }
}
Run Code Online (Sandbox Code Playgroud)

它给我一个错误,说方法[BrandsTrait]不存在.我想初始化一些东西,或者用不同的方式称呼它?

这是我的 BrandsTrait.php

<?php
namespace App\Http\Traits;

use App\Brand;

trait BrandsTrait {
    public function brandsAll() {
        // Get all the brands from the Brands Table.
        Brand::all();
    }
}
Run Code Online (Sandbox Code Playgroud)

php traits laravel laravel-5.2

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

实体框架,DBContext和using()+ async?

关于实体框架,有很长时间以来一直困扰着我.

去年我为使用EF的客户编写了一个大型应用程序.在开发过程中,一切都很顺利.

我们八月发货了.但几周后我开始在生产服务器上看到奇怪的内存泄漏.运行几天后,我的ASP.NET MVC 4进程占用了机器的所有资源(8 GB).这不好.我在网上搜索,看到你应该在一个using()块中包围所有的EF查询和操作,以便可以处理上下文.

在一天中,我重构了我要使用的所有代码using(),这解决了我的问题,因为这个过程依赖于稳定的内存使用.

我首先没有围绕我的查询的原因是我从Visualofite中包含的Microsofts自己的脚手架开始了我的第一个控制器和存储库,这些没有使用包围它的查询,而是它具有DbContext作为实例变量的控制器本身.

首先:如果处理上下文非常重要(某些事情不会很奇怪,dbconnection需要关闭等等),微软可能应该在他们的所有示例中都有这个!

现在,我已开始与我在我的后脑勺所有学习收获一个新的大项目工作,我一直在试用的.NET 4.5和EF 6的新功能asyncawait.EF 6.0具有所有这些异步方法(例如SaveChangesAsync,ToListAsync等等).

public Task<tblLanguage> Post(tblLanguage language)
{
    using (var langRepo = new TblLanguageRepository(new Entities()))
    {
        return langRepo.Add(RequestOrganizationTypeEnum, language);
    }
}
Run Code Online (Sandbox Code Playgroud)

在课堂上TblLanguageRepo:

public async Task<tblLanguage> Add(OrganizationTypeEnum requestOrganizationTypeEnum, tblLanguage language)
{
    ...
    await Context.SaveChangesAsync();
    return langaugeDb;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我现在在一个using()块中包含我的语句时,我得到异常DbContext was disposed,在查询能够返回之前.这是预期的行为.查询运行async,using块在查询之前完成.但是在使用ef 6的async和await函数时,我应该如何以适当的方式处理我的上下文?

请指出我正确的方向.

using()需要EF 6?为什么微软自己的例子从未有过这样的特色?如何正确使用异步功能并处理上下文?

.net c# asynchronous entity-framework using

25
推荐指数
3
解决办法
2万
查看次数

Git提交不会覆盖git blame中的原始作者

我使用perl脚本修改php git存储库中的所有制表符并将它们全部更改为4个空格.

$ find -iname \*.php -exec perl -pi -e "s/\t/    /g" {} \
Run Code Online (Sandbox Code Playgroud)

我可以提交这个更改git commit,但它会在我提交之后将我标记为内部所有更改行的作者git blame.

有没有办法实现这个大规模的改变,不会让我成为改变行的作者,但保留原作者?这是我们在项目中并不想丢失的很多历史.

我们用4个空格替换制表符的目的不是为了使git责备中的东西看起来不同,而是遵循适当的PEAR编码标准.例如没有标签,使用4个空格进行缩进.

git git-commit git-blame

24
推荐指数
2
解决办法
4840
查看次数