Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGrid的IEntityChangeTracker编辑行的多个实例无法引用实体对象_C#_Xml_Wpf_Entity Framework - Fatal编程技术网

C# DataGrid的IEntityChangeTracker编辑行的多个实例无法引用实体对象

C# DataGrid的IEntityChangeTracker编辑行的多个实例无法引用实体对象,c#,xml,wpf,entity-framework,C#,Xml,Wpf,Entity Framework,当我想编辑我的DataGrid的某一行时,我遇到了这个错误。。。 Xml代码: <DataGridTemplateColumn Header="ویرایش" > <DataGridTemplateColumn.CellTemplate> <DataTemplate>

当我想编辑我的DataGrid的某一行时,我遇到了这个错误。。。

Xml代码:

    <DataGridTemplateColumn Header="ویرایش" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <materialDesign:PackIcon Kind="TooltipEdit" MouseDown="Edit_OnMouseDown" Tag="{Binding Path=.}" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="ForestGreen"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
如果我从
Place
类中删除或注释关系
ICollection
和继承
BaseModel
类,这也会起作用 但是我需要它们

  public class Place:BaseModel// 
{
    [Key]
    public int PlaceId { get; set; }
    public string Name { get; set; }
    public long? PhoneNo { get; set; }
    public string Manager { get; set; }
    public string Address { get; set; }
    public short? RoomCounter { get; set; }

    public virtual ICollection<Suite> Suites { get; set; } // 
    public virtual ICollection<Bed> Beds { get; set; } //
    public virtual ICollection<Device> Devices { get; set; } //
}
公共课堂地点:BaseModel//
{
[关键]
公共int PlaceId{get;set;}
公共字符串名称{get;set;}
公共长?电话号码{get;set;}
公共字符串管理器{get;set;}
公共字符串地址{get;set;}
公共短房间计数器{get;set;}
公共虚拟ICollection套件{get;set;}//
公共虚拟ICollection床{get;set;}//
公共虚拟ICollection设备{get;set;}//
}
有什么想法吗?

试试这个:

var existingPlace=_context.Set<Place>().FirstOrDefault(i=> i.Id==place.Id);

if(existingPlace!=null)
{
 place.LastUpdate = DateTime.Now;
_context.Entry(existingPlace).CurrentValues.SetValues(place);
_context.SaveChanges();
}
  
var existingPlace=\u context.Set().FirstOrDefault(i=>i.Id==place.Id);
if(existingPlace!=null)
{
place.LastUpdate=DateTime.Now;
_context.Entry(existingPlace).CurrentValues.SetValues(place);
_SaveChanges();
}

非常感谢。。。
var existingPlace=_context.Set<Place>().FirstOrDefault(i=> i.Id==place.Id);

if(existingPlace!=null)
{
 place.LastUpdate = DateTime.Now;
_context.Entry(existingPlace).CurrentValues.SetValues(place);
_context.SaveChanges();
}