虽然我同意@tvanfosson (+1),但如果你真的想保留一个ID
,Booking
我认为这应该建立在 Booking 的构建上。你可以有类似 Booking Context 的东西,其中每个上下文都会创建带有序列 ID 的预订:
public class Booking
{
protected Booking() { }
public int Id { get; set; }
public string From { get; set; }
public string To { get; set; }
}
public class BookingContextFactory
{
private int count;
public BookingContextFactory() : this(0) { }
public BookingContextFactory(int startValue)
{
count = startValue;
}
public Booking CreateBooking(string from, string to)
{
return new InternalBooking { Id = count++, From = from, To = to };
}
private class InternalBooking : Booking
{
public InternalBooking() : base() { }
}
}