小编Max*_*Max的帖子

EF6.0"由于一个或多个外键属性不可为空,因此无法更改关系"

如果我尝试删除"子"行,我总是会遇到异常.这是一个片段:

using (var context = new CompanyContext())
{
    ItemType itemType = context.ItemTypes.FirstOrDefault(i => i.Name == "ServerType");
    ItemTypeItem itemTypeItem = itemType.Items.FirstOrDefault(i => i.Name == "DatabaseServer");
    itemType.Items.Remove(itemTypeItem);
    context.SaveChanges(); <=== exception!
}
Run Code Online (Sandbox Code Playgroud)

SaveChanges()方法抛出以下异常.

"由于一个或多个外键属性不可为空,因此无法更改关系.当对关系进行更改时,相关的外键属性将设置为空值.如果外键是如果不支持空值,则必须定义新关系,必须为foreign-key属性分配另一个非空值,或者必须删除不相关的对象."

实体配置

  public class ItemTypeConfiguration : NamedEntityConfiguration<ItemType>
  {
    public ConfigurationColumn ParentIDColumn;
    public ConfigurationColumn ValidationPatternColumn;
    public ItemTypeConfiguration() : base()
    {
      ParentIDColumn = new ConfigurationColumn() { Name = "ParentID", Ordinal = base.LastOrdinalPosition + 1 };
      ValidationPatternColumn = new ConfigurationColumn() { Name = "ValidationPattern", Length = 1024, Ordinal=base.LastOrdinalPosition + 2};
      this.Property(t …
Run Code Online (Sandbox Code Playgroud)

entity-framework fluent-interface

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

Coldfusion - 如何遍历结构数组并动态打印出所有KEY值?

给出下面的结构数组:

在此输入图像描述

我可以通过以下方式打印出所有字段中的所有值:

    <cfset ColumnNames  = structKeyArray(ApiData[1])>                       
    <cfset ColumnLength = ArrayLen(ColumnNames)>    

    <cfloop from="1" to="#ArrayLen(ApiData)#" index="i">            
       <cfdump var="#ApiData[i].Created#">              
       <cfdump var="#ApiData[i].Name#">
               ...and so on
Run Code Online (Sandbox Code Playgroud)

现在我试图遍历所有字段,这样我就不必实际写出每个字段的名称.我该如何动态执行此操作?就像是:

    <cfloop from="1" to="#ArrayLen(ApiData)#" index="i">    
      <cfloop from="1" to="#ColumnLength#" index="i">
              <!---<cfdump var="#ApiData[i]." + "#ColumnNames[i]#" + "#">--->
              <!---<cfdump var="#ApiData[i].ColumnNames[i]#">--->
      </cfloop>
    </cfloop>
Run Code Online (Sandbox Code Playgroud)

我不是ColdFusion的人,只是帮助一个伙伴和ColdFusion语法与.Net非常不同:-)

谢谢您的帮助

arrays coldfusion structure coldfusion-8

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

Angular数据表和JSON结构

这是我的问题:datatable插件只接受我相信的数组,但我的API返回一个带有数组的对象.我想弄清楚我是否需​​要提取这些信息(如何?)或者插件是否有一些方法可以帮助我(有一个):

    //the datatable plugin expects the following JSON structure
        [
            {
                "ID":"a5f415a7-3d4f-11e5-b52f-b82a72d52c35",
                "Record":1,
                "HostName":"SRX552P"
            }
        ]

    //my PHP server returns the following JSON structure:
        {
            "status":"success",
            "message":"data retrieved",
            "data":[
                    {
                        "ID":"a5f415a7-3d4f-11e5-b52f-b82a72d52c35",
                        "Record":1,
                        "HostName":"SRX552P"
                    }
                   ]                
        }    

    var allData = null;
    //this is my angularjs service where I am grabbing all the 'data':
        function getAllData() {
            dataservice.get('table001').then(function(data){
                allData = data;
            });         
            return allData;
        }

    //it looks like my issue is exactly what this post describes:
    http://stackoverflow.com/questions/27797435/accessing-json-data-in-angularjs-datatables-using-dtoptions

    //but applying ".withDataProp('data.data')" didn't work …
Run Code Online (Sandbox Code Playgroud)

json angularjs angular-datatables

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

从EF 6.0 Beta升级到RC后的System.MissingMethodException

这是什么意思?

System.MissingMethodException未由用户代码处理
HResult = -2146233069消息=未找到方法:'System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration1.Property(System.Linq.Expressions.Expression12 <!0,!! 0 >>)".Source = Att.Uds.DataLayerMappings StackTrace:位于att.Uds.DataLayerMappings.ItemTypeItemConfiguration..ctor()at at.Uds.DataLayerMappings.UdsContext.OnModelCreating(DbModelBuilder modelBuilder)in c:\ TFS\ATS-MSDev\UDS\Dev\Code\Att.Uds.DataLayerMappings\UdsContext.cs:位于System.Data.Entity.Internal.RazyInternalContext.CreateModelBuilder()处System.Data.Entity.Internal的System.Data.Entity.DbContext.CallOnModelCreating(DbModelBuilder modelBuilder)的第163行System.Data.Entity.Internal.RetryLazy2.GetValue(TInput输入)中的.LazyInternalContext.CreateModel(LazyInternalContext internalContext)InnerException:

此类发生错误:

namespace Contoso.Fabrikam.DataLayerMappings
{ 
  public abstract class NamedEntityConfiguration<TEntity> : EntityBaseConfiguration<TEntity> where TEntity : NamedEntity
  {
    public ConfigurationColumn NameColumn;
    protected new int LastOrdinalPosition
    {
      get
      {
        return (NameColumn.Ordinal);
      }
    }
    public NamedEntityConfiguration() <=== EXCEPTION HERE
    {
      NameColumn = new ConfigurationColumn() { Ordinal = base.LastOrdinalPosition+1, Name = "Name", IsRequired = true, Length = 128 };
      this.Property(t => t.Name)
        .HasColumnName(NameColumn.Name)
        .HasColumnOrder(NameColumn.Ordinal)
        .HasMaxLength(NameColumn.Length);
      if(NameColumn.IsRequired) …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

FileStream 向 TXT 文件添加“额外”字符

无论我阅读 TXT 文件还是 XML 文件,我总是看到“额外”信息添加到我保存到磁盘的文件中。我们首先执行以下操作:

FileStream fs = new FileStream(fileMoverFile.SourcePath, FileMode.Open, FileAccess.Read);
Run Code Online (Sandbox Code Playgroud)

然后我们分配fs给一个类型的变量,我们将Stream其传递给下面的函数:

private void SaveToDisk(Stream fileStream, string saveToPath)
{
  if (!Directory.Exists(Path.GetDirectoryName(saveToPath)))
  {
    Directory.CreateDirectory(Path.GetDirectoryName(saveToPath));
  }
  FileStream outputStream = new FileInfo(saveToPath).OpenWrite();
  const int bufferSize = 1024;
  byte[] buffer = new byte[bufferSize];
  int bytesRead = fileStream.Read(buffer, 0, bufferSize);
  while (bytesRead > 0)
  {
    outputStream.Write(buffer, 0, bufferSize);
    bytesRead = fileStream.Read(buffer, 0, bufferSize);
  }
  outputStream.Close();
}
Run Code Online (Sandbox Code Playgroud)

当我打开保存到磁盘的文件时,我看到额外的信息,这些信息基本上是同一个文件的一些内容与一些不属于该文件的其他信息重复。很奇怪。

什么可能导致这种情况?

c# stream filestream

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

jqGrid:使用beforeSelectRow它会禁用我的onCellSelect事件

我在这里找到了我的问题的解决方案: jqGrid multiselect - 仅使用复选框限制行的选择

但这取消了我的onCellSelect事件.简而言之,我需要能够在用户单击复选框列时选择行.上面链接中的解决方案显示了如何执行此操作但我需要能够对网格中的特定单元格执行操作,例如,当我单击第10列时,下面的代码会打开一个弹出窗口:

  onCellSelect: function (rowid, iCol, cellcontent, e) {
      if (iCol == 10) {
          OpenPopupWindow(rowid); 
      }
  },
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

jquery jqgrid

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

如何将Array转换为List但是大写?

Coldfusion 8版本在这里.这是我的代码片段:

<cfset ColumnNames  = structKeyArray(ApiData[1])>           
<cfdump var="#ColumnNames#"><!--- lowercase names --->              
<cfdump var="#ArrayToList(ColumnNames,",")#"> <!--- need each name in Array in UPPERCASE --->
Run Code Online (Sandbox Code Playgroud)

uCase(ColumnNames)不会工作.我是否必须遍历每个项目并使用uCase?

谢谢

coldfusion arraylist

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