C# Orchard 1-N关系(停止内容项更新)
背景: 这是我的轨道部件的型号:C# Orchard 1-N关系(停止内容项更新),c#,asp.net-mvc,nhibernate,orchardcms,orchardcms-1.6,C#,Asp.net Mvc,Nhibernate,Orchardcms,Orchardcms 1.6,背景: 这是我的轨道部件的型号: public class TrackPartRecord : ContentPartRecord { public virtual IList<TrackInformationRecord> Tracks { get; set; } } public class TrackPart : ContentPart<TrackPartRecord> { public IL
public class TrackPartRecord : ContentPartRecord
{
public virtual IList<TrackInformationRecord> Tracks { get; set; }
}
public class TrackPart : ContentPart<TrackPartRecord>
{
public IList<TrackInformationRecord> Tracks
{
get { return Record.Tracks; }
}
}
public class TrackInformationRecord
{
public virtual int Id { get; set; }
public virtual int TrackPartId { get; set; }
public virtual string Title { get; set; }
public virtual string Description { get; set; }
public virtual bool IsDeleted { get; set; }
public virtual IList<SessionInformationRecord> Sessions { get; set; }
}
public class SessionInformationRecord
{
public virtual int Id { get; set; }
public virtual int TrackId { get; set; }
public virtual string Title { get; set; }
public virtual string Description { get; set; }
public virtual DateTime Timeslot { get; set; }
public virtual bool HasEvaluation { get; set; }
public virtual bool IsDeleted { get; set; }
}
内容项附加跟踪部分(形成1-n关系),跟踪记录具有会话记录列表
添加轨迹时,问题开始出现。将添加第一个添加的轨迹。在第一次更新之后(添加第一首曲目,还没有会话),我不再能够更新内容项上的任何内容。当我浏览代码时,我没有得到任何错误或异常(可能它们埋在Orchard中太深了,没有直接抛出任何明显的东西)
当我直接进入数据库并删除与内容项相关的跟踪记录时,我能够再次更新所有内容
我检查了日志,发现:
2013-08-14 14:15:00,882 [30] NHibernate.AdoNet.AbstractBatcher - Could not execute command: UPDATE Ignite_EventsAgenda_SessionInformationRecord SET TrackInformationRecord_id = null WHERE TrackInformationRecord_id = @p0
System.Data.SqlServerCe.SqlCeException (0x80004005): The column name is not valid. [ Node name (if any) = ,Column name = TrackInformationRecord_id ]
at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
2013-08-14 14:15:00,888 [30] NHibernate.Util.ADOExceptionReporter - System.Data.SqlServerCe.SqlCeException (0x80004005): The column name is not valid. [ Node name (if any) = ,Column name = TrackInformationRecord_id ]
at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Persister.Collection.AbstractCollectionPersister.Remove(Object id, ISessionImplementor session)
2013-08-14 14:15:00,891 [30] NHibernate.Util.ADOExceptionReporter - The column name is not valid. [ Node name (if any) = ,Column name = TrackInformationRecord_id ]
2013-08-14 14:15:00,894 [30] NHibernate.Event.Default.AbstractFlushingEventListener - Could not synchronize database state with session
NHibernate.Exceptions.GenericADOException: could not delete collection: [Ignite.EventsAgenda.Models.TrackInformationRecord.Sessions#1][SQL: UPDATE Ignite_EventsAgenda_SessionInformationRecord SET TrackInformationRecord_id = null WHERE TrackInformationRecord_id = @p0] ---> System.Data.SqlServerCe.SqlCeException: The column name is not valid. [ Node name (if any) = ,Column name = TrackInformationRecord_id ]
首先,我不知道为什么会出现“列名无效”的问题
其次,我不明白这一行:updateignite\u EventsAgenda\u SessionInformationRecord SET TrackInformationRecord\u id=null,其中TrackInformationRecord\u id=@p0
它从哪里获得了列名称TrackInformationRecord\u id
任何帮助或建议都将不胜感激。是的,应该用斜杠命名,类型可以用记录类名而不是int。您还应该将Datetime设置为nullable:Datetime?您可以这样尝试吗(为了简单起见,我省略了会话,但您可以复制相同的内容):
公共类TrackPartRecord:ContentPartRecord
{
公共虚拟IList跟踪{get;set;}
}
公共类轨道信息记录
{
//自有财产
公共虚拟整数Id{get;set;}
公共虚拟字符串标题{get;set;}
公共虚拟字符串描述{get;set;}
公共虚拟布尔被删除{get;set;}
//关系性质
公共虚拟TrackPartRecord TrackPartRecord{get;set;}
}
在移民方面:
SchemaBuilder.CreateTable("TrackPartRecord", t => t
.ContentPartRecord()
);
SchemaBuilder.CreateTable("TrackInformationRecord", t => t
.Column<int>("Id", column => column.PrimaryKey().NotNull())
.Column<int>("TrackPartRecord_Id")
.Column<string>("Title", c => c.WithLength(50).NotNull())
.Column<string>("Description", c => c.NotNull())
.Column<bool>("IsDeleted")
);
schemabilder.CreateTable(“TrackPartRecord”,t=>t
.ContentPartRecord()
);
CreateTable(“TrackInformationRecord”,t=>t
.Column(“Id”,Column=>Column.PrimaryKey().NotNull())
.列(“TrackPartRecord\u Id”)
.Column(“Title”,c=>c.WithLength(50).NotNull()
.Column(“Description”,c=>c.NotNull())
.栏(“删除”)
);
public class TrackPartRecord : ContentPartRecord
{
public virtual IList<TrackInformationRecord> Tracks { get; set; }
}
public class TrackInformationRecord
{
// Own properties
public virtual int Id { get; set; }
public virtual string Title { get; set; }
public virtual string Description { get; set; }
public virtual bool IsDeleted { get; set; }
// Relations properties
public virtual TrackPartRecord TrackPartRecord { get; set; }
}
SchemaBuilder.CreateTable("TrackPartRecord", t => t
.ContentPartRecord()
);
SchemaBuilder.CreateTable("TrackInformationRecord", t => t
.Column<int>("Id", column => column.PrimaryKey().NotNull())
.Column<int>("TrackPartRecord_Id")
.Column<string>("Title", c => c.WithLength(50).NotNull())
.Column<string>("Description", c => c.NotNull())
.Column<bool>("IsDeleted")
);
public class TrackInformationRecord
{
public virtual IList<SessionInformationRecord> Sessions { get; set; }
}
public class TrackInformationRecordOverride
: IAutoMappingOverride<TrackInformationRecord>
{
public void Override(AutoMapping<TrackInformationRecord> mapping)
{
mapping.HasMany(x => x.Sessions)
.KeyColumn("TrackId"); // ... assuming TrackId is the column you wanted.
}
}