小编Stu*_*ang的帖子

将Entity Framework EDMX转换为Code First的工具

是否有工具将edmx转换为代码优先?我知道有一段时间在CTP中出现了一个,但我找不到与此相关的任何更新.

MSDN论坛上有一个人写了他自己的(现在还没有),但EF团队没有.

.net entity-framework code-first edmx

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

实体框架代码迁移 - 陷入初始迁移

我已经通过Nuget将EF 5添加到我的项目中,并使用"Enable-Migrations"命令启用了迁移.然后我调用"Add-Migration"来生成用于生成模式的基本代码.

然后我向我的一个域对象添加了一个属性(名为"TestProperty"的字符串属性)并添加了一个映射到我的EntityTypeConfiguration文件(我们暂时忽略了这些约定).

再次调用"Add-Migration"会产生错误:

Unable to generate an explicit migration because the following explicit migrations are pending: [201303262144218_Initial]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
Run Code Online (Sandbox Code Playgroud)

但是调用"Update-Database"会产生一个sql异常,因为这些表已经存在:

There is already an object named 'Customer' in the database
Run Code Online (Sandbox Code Playgroud)

在我的DbContext的构造函数中,我尝试了不同的更新策略,例如:

Database.SetInitializer<UnitOfWork>(new DropCreateDatabaseAlways<UnitOfWork>());
Run Code Online (Sandbox Code Playgroud)

我错过了一些明显的东西吗 我在这里尝试了解决方案,但它不起作用:ASP.NET的自动迁移

谢谢

编辑:更新完成第一步的关键是创建初始迁移,然后从Up和Down方法中删除生成的代码(http://thedatafarm.com/blog/data-access/using-ef-migrations- with-an-existing-database /).

然后,我可以更新模型和EF映射,然后运行Add-Migration.这会使用正确的Up和Down代码生成迁移.

然后问题是尝试应用更新.Update-Database产生错误"无法更新数据库以匹配当前模型,因为存在挂起的更改并禁用自动迁移...自动迁移.将DbMigrationsConfiguration.AutomaticMigrationsEnabled设置为true以启用自动迁移.您可以使用Add-Migration命令将挂起的模型更改写入基于代码的迁移".好的,所以我再次尝试添加迁移,它会生成另一个迁移,其代码与最后一个完全相同.

我运行Update-Database并再次获得相同的错误.我尝试"Update-Database -TargetMigration 201304080859556_MyMigration -Force",但这会产生"指定的目标迁移'201304080859556_MyMigration'不存在.确保目标迁移是指现有的迁移ID" - 确实如此!

很沮丧!

entity-framework code-migration ef-code-first entity-framework-5

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

SignalR不再工作"找不到包含OwinStartupAttribute的程序集"

我有一个使用SignalR的Web API项目,它开始让我"经常无法找到Microsoft.AspNet.Signal.Core"错误,这些错误只能通过在Visual Studio中进行完全重建来解决.

我在Nuget中升级了SignalR和OWIN以尝试修复此问题,但现在我总是得到"尝试加载应用程序时出现以下错误. - 找不到包含OwinStartupAttribute的程序集. - 找不到包含Startup或[AssemblyName]的程序集.Startup类"

我是团队中唯一一个得到此错误的人 - 相同的代码在其他计算机上运行正常.

我有一个启动类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(MyProject.Startup))]
namespace MyProject
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试将AppStartup键添加到web.config中:

<add key="owin:appStartup" value="MyProject.Startup, MyProject" />
Run Code Online (Sandbox Code Playgroud)

我在WebApi项目中有以下参考:

Microsoft.AspNet.SignalR.Core (2.1.0.0)
Microsoft.AspNet.SignalR.SystemWeb (2.1.0.0)
Microsoft.Owin (2.0.2.0)
Microsoft.Owin.Host.SystemWeb (2.0.2.0)
Microsoft.Owin.Security (2.0.2.0)
Owin (1.0.0)
Run Code Online (Sandbox Code Playgroud)

我在Windows 8 64Bit上使用IIS 8.5

asp.net signalr asp.net-web-api owin

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

内容控制内容调整以填充Silverlight 4

我有一个ContentControl的样式,我想在我目前有边框的地方使用它.当我使用它时,子控件不会伸展到填充,只占用少量空间.我已经尝试将Horizo​​ntalAlignment ="Stretch"应用于所有内容,但它不起作用.怎么了?

<Style x:Key="GradientPanel" TargetType="ContentControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl">
                <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <Rectangle RadiusY="10" RadiusX="10" Stroke="Black" StrokeThickness="0">
                        <Rectangle.Effect>
                            <DropShadowEffect Opacity="0.56" ShadowDepth="1" BlurRadius="3" />
                        </Rectangle.Effect>
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFE1EAF3"/>
                                <GradientStop Color="White" Offset="1"/>
                                <GradientStop Color="#FFFAFBFD" Offset="1"/>
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <ContentPresenter Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

...

之前(工作正常):

<Border Style="{StaticResource SearchContainerBorder}" >
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <ToggleButton  Style="{StaticResource ToggleButtonExpanderStyle}" Grid.Row="0" Grid.Column="1" Height="25" Width ="25" HorizontalAlignment="Center" …
Run Code Online (Sandbox Code Playgroud)

silverlight contentcontrol

13
推荐指数
1
解决办法
9648
查看次数

仅用于内容文件的 Nuget 包

我正在尝试创建一个 .NET 标准 nuget 内容文件包(没有托管程序集),供 .NET Framework 程序集使用。我的目标是将此文件文件夹复制到消费程序集的 bin 文件夹中。

这个问题类似于Add native files from NuGet package to project output directory(并使用这个 nuget 包http://www.nuget.org/packages/Baseclass.Contrib.Nuget.Output/),但我需要我的 nuget 包.NET 标准

我已经在 contentfiles\any\any\myfiles 下的程序集中添加了文件,并将以下内容添加到 nuspec 文件的元数据部分:

<contentFiles>
    <files include="any/any/myfiles/*" buildAction="None" copyToOutput="true" />
</contentFiles>
Run Code Online (Sandbox Code Playgroud)

当我尝试将其添加到 .NET 框架程序集时,出现错误

无法安装包“myPackage 1.0.0”。您正在尝试将此包安装到以“.NETFramework,Version=v4.6.2”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。有关更多信息,请联系软件包作者。

我还尝试将文件添加到项目的根目录,并在 nuspec 文件的元数据元素下方添加以下内容:

<files>
    <file src="myfiles\**\*" target="myfiles" />
</files>
Run Code Online (Sandbox Code Playgroud)

完整的 nuspec 文件:

<?xml version="1.0"?>
<package>
    <metadata>
        <id>myPackage</id>
        <version>1.0.0</version>
        <title>myPackage</title>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>my files/description>
        <releaseNotes></releaseNotes>
        <tags></tags>
        <contentFiles>
            <files include="any/any/myfiles/*" buildAction="None" copyToOutput="true" />
        </contentFiles>
    </metadata>
    <files>
        <file …
Run Code Online (Sandbox Code Playgroud)

.net c# nuget .net-standard

9
推荐指数
1
解决办法
5722
查看次数

由于EF代码迁移,Teamcity构建失败

我的TeamCity构建失败,因为我有一个项目,其中包含2个EF代码迁移配置.

从构建日志:

[12:39:58]Checking for changes
[12:39:58]Collecting changes in 1 VCS root (1s)
[12:40:00]Clearing temporary directory: C:\TeamCity\buildAgent2\temp\buildTmp
[12:40:00]Publishing internal artifacts
[12:40:00]Checkout directory: C:\TeamCity\buildAgent2\work\1679b8b30e00ad0
[12:40:00]Updating sources: server side checkout (2s)
[12:40:03]Step 1/8: Gulp (Command Line)
[12:40:03]Step 2/8: Nuget Package Refresh (NuGet Installer) (3s)
[12:40:06]Step 3/8: Compile (MSBuild) (21s)
[12:40:27]Step 4/8: Unit Tests (NUnit) (33s)
[12:41:01]Step 5/8: Transform Files (Powershell) (2s)
[12:41:03]Step 6/8: Deployment Build on XXXXX Live (MSBuild) (25s)
[12:41:29]Step 7/8: Deploy Database (Powershell) (5s)
[12:41:34]Step 8/8: Deploy Portal.Hub (Powershell) (33s)
[12:42:08]Publishing …
Run Code Online (Sandbox Code Playgroud)

teamcity entity-framework-4 ef-migrations teamcity-8.0

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

在 Windows 中检查 OSX (.dmg) 文件的数字签名

我当前正在使用 WinVerifyTrust api 检查 Windows 安装程序文件 (.msi) 的数字签名在 C# 中是否有效。我还在验证签名中的指纹是否来自已知列表。

我需要对 C# 中的 Mac OSX 文件 (.dmg)(在 Windows 上)执行相同的操作。有什么办法可以做到这一点吗?

.net c# authenticode digital-signature winverifytrust

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

Identity Server:在MVC客户端的混合流中添加对访问令牌的声明

我已阅读文档并按照示例操作,但我无法将用户声明置于访问令牌中.我的客户端不是ASP.NET核心,因此MVC客户端的配置与v4示例不同.

除非我误解了文档,否则ApiResources用于在创建访问令牌时填充配置文件服务中的RequestedClaimTypes.客户端应将api资源添加到其范围列表中以包含关联的用户声明.在我的情况下,他们没有连接.

使用调用者"ClaimsProviderAccessToken"调用ProfileService.GetProfileDataAsync时,请求的声明类型为空.即使我在这里设置context.IssuedClaims,当再次为"AccessTokenValidation"调用它时,也不会设置上下文中的声明.

在MVC应用程序中:

    app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                UseTokenLifetime = false, 
                ClientId = "portal",
                ClientSecret = "secret",
                Authority = authority,
                RequireHttpsMetadata = false,
                RedirectUri = redirectUri,
                PostLogoutRedirectUri = postLogoutRedirectUri,
                ResponseType = "code id_token",
                Scope = "openid offline_access portal",
                SignInAsAuthenticationType = "Cookies",
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthorizationCodeReceived = async n =>
                    {
                        await AssembleUserClaims(n);
                    },
                    RedirectToIdentityProvider = n =>
                    {
                        // if signing out, add the id_token_hint
                        if (n.ProtocolMessage.RequestType == Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectRequestType.Logout)
                        {
                            var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                            if (idTokenHint != null) …
Run Code Online (Sandbox Code Playgroud)

c# oauth identityserver4

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

无法在Windows的Docker中运行容器:“系统找不到指定的文件”

我有一个简单的C#控制台应用程序:

static void Main(string[] args)
{
    Console.WriteLine("TESTING!");
    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

和一个DockerFile:

FROM microsoft/windowsservercore
WORKDIR /app
COPY /bin/Debug .
ENTRYPOINT ["dotnet","TestApp.exe"]
Run Code Online (Sandbox Code Playgroud)

我建立了一个图像:

docker build -f dockerfile -t testapp .
Run Code Online (Sandbox Code Playgroud)

然后,我尝试运行它:

docker run testapp
Run Code Online (Sandbox Code Playgroud)

出现此错误:

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: 
Error response from daemon: container a728cbed9188640df1d6e2f5c4d75f3ae3faef6162ec978575f9a587ed6546eb encountered an error during CreateProcess: 
failure in a Windows system call: 
The system cannot find the file specified. (0x2) extra info:
{"CommandLine":"dotnet TestApp.exe","WorkingDirectory":"C:\\app","CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.
Run Code Online (Sandbox Code Playgroud)

是否找不到TestApp.exe?

c# docker docker-for-windows

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

Azure SQL Serverless 层永远不会关闭

我正在尝试 Azure SQL 中的无服务器层,但数据库从不“休眠”,因为 Azure 似乎在后台不断查询数据库。我通过 ARM 模板创建了数据库。

数据库概览中的“计算利用率”和“应用 CPU 计费”图表显示数据库经常被访问(即使我自己没有进行任何查询)。“查询性能洞察”中的热门查询是:

(@ip_address_value bigint,@start_ip varchar(45))SELECT top 1 @start_ip = start_ip_address_value FROM sys.database_firewall_rules_table WHERE @ip_address_value BETWEEN start_ip_address_value AND end_ip_address_value OPTION (MAXDOP 1)
Run Code Online (Sandbox Code Playgroud)

(@ip_address_value bigint,@start_ip varchar(45))SELECT top 1 @start_ip = start_ip_address_value FROM sys.database_firewall_rules_table WHERE @ip_address_value BETWEEN start_ip_address_value AND end_ip_address_value AND start_ip_address_value > 0 OPTION (MAXDOP 1)
Run Code Online (Sandbox Code Playgroud)

这似乎是从防火墙。我是否必须禁用防火墙或删除所有规则才能让数据库“休眠”?

azure azure-sql-database azure-sql-server

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

在PowerShell中返回具有单个元素的数组

这应该很简单——我需要从一个函数返回一个哈希表数组。这在有多个哈希表时有效,但当只有一个时,结果不是数组。我宁愿不测试结果是否为数组。

function GetArrayWith1Hashtable()
{
    $array = @()

    $hashtable = @{}
    $hashtable["a"] = "a" 
    $hashtable["b"] = "b" 
    $hashtable["c"] = "c"
    $array += $hashtable 

    Write-Host "GetArrayWith1Hashtable array.Length =" $array.Length
    Write-Host "GetArrayWith1Hashtable array.Count" $array.Count
    Write-Host "GetArrayWith1Hashtable array[0].Keys" $array[0].Keys

    $array
}

function GetArrayWith2Hashtables()
{
    $array = @()

    $hashtable = @{}
    $hashtable["a"] = "a" 
    $hashtable["b"] = "b" 
    $hashtable["c"] = "c"
    $array += $hashtable 

    $hashtable2 = @{}
    $hashtable2["d"] = "d" 
    $hashtable2["e"] = "e"
    $hashtable2["f"] = "f"
    $array += $hashtable2 

    Write-Host "GetArrayWith2Hashtables array.Length = " $array.Length
    Write-Host …
Run Code Online (Sandbox Code Playgroud)

arrays powershell hashtable powershell-5.0

5
推荐指数
2
解决办法
2225
查看次数

在 PowerShell 中使用特定配置文件启动 Chrome

我尝试使用特定的用户配置文件(--profile-directory 参数)在 PowerShell 中启动 Chrome,但它会创建一个新的配置文件。

我试过了:

& "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory=Foobar

& "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --profile-directory=Foobar"

& "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --profile-directory='Foobar'"

Start-Process "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory=Foobar

Start-Process "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --profile-directory=Foobar"
Run Code Online (Sandbox Code Playgroud)

ETC....

windows powershell google-chrome user-profile

4
推荐指数
1
解决办法
8975
查看次数

无法在Visual Studio 2017中调试.NET核心项目

我有一个Service Fabric应用程序,有几个服务 - 一些.NET核心,一些不是.所有项目的目标框架是.NET 4.6.2.我团队的其他成员能够在核心项目中遇到断点,但在我的机器上,符号永远不会被加载.非核心项目中的断点正常.

我尝试清理解决方案,重建,重新启动Visual Studio并将Visual Studio升级到15.5.0(从15.3开始).

我正在运行Debug构建(x64).

我还尝试在调试设置中明确添加输出文件夹作为符号位置.

visual-studio .net-core azure-service-fabric

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