【发布时间】:2014-12-04 04:31:17
【问题描述】:
假设我有一个ListingEvent 类和一个UserAccount 类。
ListingEvent 可以有多个UsersAttending,UserAccount 可以参加多个ListingEvents。
类看起来像:
public class UserAccount
{
[AutoIncrement]
[PrimaryKey]
public int Id {
get ;
set;
}
public string Name {
get ;
set;
}
public UserAccount()
{
ListingEventsAttending = new List<UserAccountListingEvent> ();
}
[Reference]
public List<UserAccountListingEvent> ListingEventsAttending {
get;
set;
}
}
public class UserAccountListingEvent{
[AutoIncrement]
[PrimaryKey]
public int Id {
get;
set;
}
public Model.AttendingStatus Status { get; set; }
[References(typeof(UserAccount))]
public int UserAccountId {
get;
set;
}
[References(typeof(ListingEvent))]
public int ListingEventId {
get;
set;
}
}
public class ListingEvent
{
public ListingEvent()
{
UsersAttending = new List<UserAccountListingEvent>();
}
[AutoIncrement]
[PrimaryKey]
public int Id {
get ;
set;
}
public string Name { get; set; }
[Reference]
public List<UserAccountListingEvent> UsersAttending { get; set; }
public void RemoveUserAttending(UserAccount user)
{
if (user == null)
{
return;
}
UsersAttending.RemoveAll(u => u.UserAccountId == user.Id);
}
}
我得到一个 ListEvent,我的 UserAccount 参加了:
var listingEvent = db.LoadSingleById<Model.ListingEvent> (request.Id);
我可以看到具有正确 ID 的用户正在参加,因此请致电 RemoveUserAttending 删除该用户。我现在可以看到用户没有参加,所以我打电话:
db.Save (listingEvent, references: true);
但是 - 现在,当我再次去获取该 ListingEvent 时,用户又回来参加了。
所以我的问题是:
- 以上是否应该按预期工作?
- 如果没有,我应该怎么做?
【问题讨论】:
标签: servicestack ormlite-servicestack