错误信息 :
附加"FaridCRMData.Models.Customer"类型的实体失败,因为同一类型的另一个实体已具有相同的主键值.
Attach()如果图中的任何实体具有冲突的>键值,则在使用该方法或将实体的状态设置为"未更改"或"已修改" 时,可能会发生这种情况.这可能是因为某些实体是新的并且尚未收到数据库生成的键值.在这种情况下,使用"添加"方法或"已添加"实体状态来跟踪图形,然后根据需要将非新实体的状态设置为"未更改"或"已修改".
我的代码:
public class FactorController : Controller
{
public JsonResult SaveFactor(Factor factor,int id)
{
if (id > 0)
{
bool result = new FactorService.BaseService.Update(factor);
return new JsonResult() { Data = result };
}
}
}
Run Code Online (Sandbox Code Playgroud)
FactorService.BaseService.cs:
public bool Update(TEntity entity)
{
var entry = context.Entry(entity);
if (entry.State == EntityState.Detached || entry.State == EntityState.Modified)
{
context.Set<TEntity>().Attach(entity);// Error Is Here
entry.State = EntityState.Modified;
context.SaveChanges();
}
return true;
}
Run Code Online (Sandbox Code Playgroud) 我试图使用.NET版本4.6.1在ASP.NET MVC 5应用程序中使用C#7中的新元组功能.和Visual Studio 2017 RC.为此,我在这里引用了这篇文章:C#7中有什么新东西,它说要通过NuGet安装System.ValueTuple.当我这样做时,元组语法开始为我工作,就像在这个示例代码中:
public void TupleCaller()
{
(var valOne, var valTwo) = TupleExample();
}
public (string, string) TupleExample()
{
return ("Tuple Item One", "Tuple Item Two");
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行应用程序时,我的视图会立即抛出此错误:
CS0012:类型'System.Object'在未引用的程序集中定义.您必须添加对程序集'System.Runtime,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用.
我尝试了以下所有方法:
一旦卸载System.ValueTuple NuGet包并注释掉新的Tuple代码,所有内容都会像以前一样在视图中正确呈现.
我在Mac(OSX)上为学校构建了一堆简单的C程序.我编译了所有程序,并在我的Mac上用Makefile对它们进行了全部测试.一切都运作良好.
为了明天准备作业,我决定通过SSH将所有这些文件(编译和源代码)传输到类网络(操作系统是Ubuntu).我想确保一切按预期工作.
一旦我转移了所有内容,当我尝试使用Emacs shell运行已编译的程序时,我收到了一个Cannot execute binary file错误.然后,一旦我通过Ubuntu机器上的SSH通过我的Makefile重新编译,它运行正常.但为什么不呢?
我知道这对你们中的一些人来说是显而易见的,但我不知道为什么编译的C程序在我的机器上运行正常,但是即使操作系统不同,也必须在不同的机器上重新编译?
以下是我的Makefile编译命令的示例:
example: example.c
gcc -Wall -pedantic -ansi example.c -o example
Run Code Online (Sandbox Code Playgroud)
我很擅长C(显然).这个问题,为什么我的程序在Ubuntu gcc上运行但不在OSX gcc上运行?,似乎相似,但我不明白答案.
我有一个用 Python 构建的 Plotly 图形,可以自动更新。即使自动更新,我也想保留仪表板缩放。Plotly 中的文档表示,uirevision根据此社区文章,可以使用布局字段来完成此操作。文档给出了返回字典的示例:
return {
'data': data,
'layout': {
# `uirevsion` is where the magic happens
# this key is tracked internally by `dcc.Graph`,
# when it changes from one update to the next,
# it resets all of the user-driven interactions
# (like zooming, panning, clicking on legend items).
# if it remains the same, then that user-driven UI state
# doesn't change.
# it can be equal to anything, the important …Run Code Online (Sandbox Code Playgroud) 所以我在本地安装了pecl oauth模块,这一切都很完美.然后我尝试为生产服务器执行此操作但遇到了一些问题.
如果我说sudo pecl install oauth,我会收到此错误:
No releases available for package "pecl.php.net/oauth"
install failed
Run Code Online (Sandbox Code Playgroud)
所以我想我必须更新pecl.php.net,所以我尝试了命令sudo pecl channel-update pecl.php.net,但后来我得到了这个输出:
Updating channel "pecl.php.net"
Channel "pecl.php.net" is not responding over http://, failed with message:
Connection to 'pecl.php.net:80' failed: Connection refused
Trying channel "pecl.php.net" over https:// instead
Cannot retrieve channel.xml for channel "pecl.php.net" (Connection to `pecl.php.net:443' failed: Connection refused)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我创建了一个名为AddNewInventoryViewModel的ViewModel(Project是使用运行时.NET Core 5.0在OSX上使用Visual Studio Code的ASP.NET MVC)并将其添加到ViewModel models文件夹中,因此我有以下结构:
ViewModels/Home/AddNewInventoryViewModel.cs
Views/Home/AddNewInventory.cshtml
Run Code Online (Sandbox Code Playgroud)
我的观点看起来像这样:
@model AddNewInventoryViewModel
...Content here
Run Code Online (Sandbox Code Playgroud)
我的Home控制器动作方法如下所示:
[HttpGet]
public IActionResult AddNewInventory()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
为简洁起见,我不会包含ViewModel.cs文件本身.
但是,当我访问我的应用程序页面(AddNewInventory.cshtml)时,我收到错误:
DNXCore,Version=v5.0 error CS0246: The type or namespace
'AddNewInventoryViewModel' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
为什么错误?我错过了什么?
在Visual Studio 2015 Update 3中,我正在构建一个Node.js应用程序,并使用Vash作为视图引擎.但是,当我在vash文件中编写HTML时,语法突出显示不起作用.它只是显示为纯文本.例如,这个:
<!DOCTYPE html>
<html>
<head>
<title>@model.title</title>
</head>
<body>
<div>@model.block("body")</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
只会出现没有任何亮点.
当我尝试在Visual Studio 2015 Update 2中合并cshtml文件时,我一直收到这个通用错误,然后VS会崩溃:我检查了日志,但它们根本没用.如下所示,错误是遇到异常.这可能是由扩展引起的.
这可能是抛出错误的地方.不确定
<entry>
<record>3863</record>
<time>2016/07/20 14:11:46.766</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.ArgumentNullException: Value cannot be null.
Parameter name: key
 at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
 at Microsoft.VisualStudio.Html.Package.Extensions.ExtensionsManager.OnTextViewCreated(ITextView textView, ITextBuffer textBuffer)
 at Microsoft.Web.Editor.Controller.TextViewConnectionListener.OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer)
 at Microsoft.VisualStudio.Html.Package.Commands.Html.VsHtmlTextViewConnectionListener.OnTextViewGotAggregateFocus(ITextView textView, ITextBuffer textBuffer)
 at Microsoft.Web.Editor.Controller.TextViewConnectionListener.<>c__DisplayClass24_0.<OnTextViewConnected>b__0(Object sender, EventArgs eventArgs)
 at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent(Object sender, EventHandler eventHandlers)</description>
</entry>
<entry>
Run Code Online (Sandbox Code Playgroud)
这使得我必须手动合并我的cshtml文件.我尝试修复VS 2015并试图禁用一堆扩展,但它仍然存在.