I know this is probably asked all the time, but this is more of "I can't see it".
Me and another developer have sat down and tried to figure out why this one particular enum value causes this issue. With the enum i get this error, without it it succeeds.
I am using fluent nhibernate for my mappings and conventions.
I supplied all relevant information regarding this issue.
Code:
public class Listing : Entity
{
public virtual bool Active { get; set; }
public virtual bool Archived { get; set; }
public virtual bool AutoAccept { get; set; }
public virtual bool Completed { get; set; }
public virtual bool Deleted { get; set; }
public virtual bool DeliveryInside { get; set; }
public virtual bool MatchComplete { get; set; }
public virtual bool PickupInside { get; set; }
public virtual DateTime? AuctionEndDate { get; set; }
public virtual DateTime? DateCreated { get; set; }
public virtual DateTime? DateUpdated { get; set; }
public virtual DateTime? ExpiresOn { get; set; }
public virtual DateTime? TimeframeEarliestDelivery { get; set; }
public virtual DateTime? TimeframeEarliestPickup { get; set; }
public virtual DateTime? TimeframeLatestDelivery { get; set; }
public virtual DateTime? TimeframeLatestPickup { get; set; }
public virtual decimal Mileage { get; set; }
public virtual decimal TotalWeight { get; set; }
public virtual int AffiliateID { get; set; }
public virtual int BidTypeID { get; set; }
public virtual int CategoryID { get; set; }
public virtual int Commodity2ID { get; set; }
public virtual int ControlVersion { get; set; }
public virtual int GeneratedId { get; set; }
public virtual int ListingDuration { get; set; }
public virtual int OriginalPackageTypeID { get; set; }
public virtual int PackageTypeID { get; set; }
public virtual int PackageVersion { get; set; }
public virtual int SubcategoryID { get; set; }
public virtual int Views { get; set; }
public virtual int PickupAddressTypeID { get; set; }
public virtual int DropoffAddressTypeID { get; set; }
public virtual string AuctionBuyerID { get; set; }
public virtual string AuctionImageURL { get; set; }
public virtual string AuctionItemID { get; set; }
public virtual string CurrentStatus { get; set; }
public virtual string Description { get; set; }
public virtual string image1FileName { get; set; }
public virtual string PreviousStatus { get; set; }
public virtual string RecipientName { get; set; }
public virtual string RecipientPhone1 { get; set; }
public virtual string SenderName { get; set; }
public virtual string SenderPhone1 { get; set; }
public virtual string Title { get; set; }
public virtual TimeFrameType DeliveryTimeFrameTypeId { get; set; } // This causes the error
public virtual IList<ListingQuestion> Questions { get; protected set; }
public virtual bool IsBrokered()
{
return false;
}
public virtual ListingQuestion GetRootQuestion(int questionID)
{
return null;
}
public virtual IEnumerable<ListingQuestion> GetQuestionThread(int questionID)
{
return null;
}
public virtual IEnumerable<ListingQuestion> GetUnansweredQuestions()
{
return null;
}
}
Code:
public class ListingOverride : IAutoMappingOverride<Listing>
{
public void Override(AutoMapping<Listing> mapping)
{
mapping.Id(x => x.Id, "PackageID");
mapping.Map(x => x.Completed, "MatchComplete");
mapping.Map(x => x.ExpiresOn, "ExpirationDate");
}
}
Code:
public class EnumConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(p => p.Property.PropertyType.IsEnum);
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType(instance.Property.PropertyType);
}
}
Code:
public class ListingQuestion : Entity
{
#region Built-in types
public virtual bool AnswerReported { get; set; }
public virtual bool HideQuestion { get; set; }
public virtual bool QuestionReported { get; set; }
public virtual DateTime? AnsweredOn { get; set; }
public virtual DateTime? AskedOn { get; set; }
public virtual int ParentQuestionID { get; set; }
public virtual int QuestionFlagStatus { get; set; }
public virtual int UserID { get; set; }
public virtual string Answer { get; set; }
public virtual string Question { get; set; }
#endregion
#region Entity types
public virtual Listing Listing { get; set; }
#endregion
}
Code:
public class ListingQuestionOverride : IAutoMappingOverride<ListingQuestion>
{
public void Override(AutoMapping<ListingQuestion> mapping)
{
mapping.Id(x => x.Id).Column("QuestionID");
mapping.Map(x => x.AnsweredOn).Column("DateAnswered");
mapping.Map(x => x.AskedOn).Column("DateCreated");
mapping.Map(x => x.HideQuestion).Column("QuestionHide");
mapping.References(x => x.Listing).Column("PackageID");
}
}
Code:
public IList<ListingQuestion> GetListingQuestions(int userID)
{
return Transact<IList<ListingQuestion>>(() =>
session.QueryOver<ListingQuestion>()
.Where(q => q.AnsweredOn == null)
.And(q => q.UserID == 266795)
.JoinQueryOver<Listing>(q => q.Listing)
//.Where(l => l.Lister.Id == userID && !l.Completed && !l.Archived)
//.And(l => l.Active && !l.Deleted && l.ExpiresOn > DateTime.Now)
.List());
}
Code:
protected virtual TResult Transact<TResult>(Func<TResult> func)
{
if (!session.Transaction.IsActive)
{
TResult result;
using (var trans = session.BeginTransaction())
{
result = func.Invoke();
trans.Commit(); // This is where the error happens.
}
return result;
}
return func.Invoke();
}