我有一个实体,我们称它为CommonEntity主键,在许多其他实体中用作外键.随着应用程序的开发,这些链接将继续增长.
我想要一种方法来查看是否CommonEntity可以安全删除(即它没有被任何其他实体使用).
我意识到我能做到
if(!ce.EntityA.Any() && !ce.EntityB.Any() ... && !ce.EntityN.Any())
{
//Delete
}
Run Code Online (Sandbox Code Playgroud)
但是我希望能够自动检查所有关系,因为我不喜欢每次添加新关系时都必须手动更改此代码.也许EF4 +中有一些我不知道的东西?
我认为有可能使用事务范围来尝试删除对象并在它失败时将其回滚,但我不确定这种方法是否存在任何不良副作用.
有更好的方法吗?
编辑:看起来VS2012使用EF5即使项目是.Net 4,所以它创建了POCO模型,即使它是从数据库生成的.
我正在尝试从 VS 包管理器控制台连接到 SQL Azure 数据库 - 例如
Update-Database -ConnectionString "Some connection string that let's me connect with AzureAD MFA" -ConnectionProviderName "System.Data.SqlClient"
Run Code Online (Sandbox Code Playgroud)
我得到的最接近的是使用此连接字符串,但我收到一条错误,指出需要 MFA,这是有道理的!是否有另一种方法可以指定通过 AAD 进行身份验证的连接并提示我进行 MFA,类似于 SSMS 的方式?
entity-framework visual-studio azure-active-directory azure-sql-database
我想在我的Azure部署中安装IP和域限制功能,但我使用的是os版本3(Server 2012),它已经弃用了ServerManageCmd,因此以下代码不起作用:
StartupTask.cmd
@echo off
@echo Installing "IPv4 Address and Domain Restrictions" feature
%windir%\System32\ServerManagerCmd.exe -install Web-IP-Security
@echo Unlocking configuration for "IPv4 Address and Domain Restrictions" feature
%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity
Run Code Online (Sandbox Code Playgroud)
ServiceDefinition.csdef partial
<Startup>
<Task commandLine="Startup\StartupTasks.cmd" executionContext="elevated" taskType="simple" />
</Startup>
Run Code Online (Sandbox Code Playgroud)
我相信我需要使用powershell命令,但我在这里有点不太深入.任何人都可以提供2012年此代码的等价物吗?