This must be something simple somewhere I can't get hold of.
Say a business offers multiple services. Business on one side, ServiceOffers as lookup table and a BusinessServiceOffers for the association. When I add a many-to-one mapping like below, sqlite provider(while unit testing) threw an argument out of range exception, understandably due to the duplicate reference in both Property and ManyToOne.
Property(x => x.ServiceOfferingId);
ManyToOne
(
x => x.ServiceOffering,
x =>
{
x.Fetch(FetchKind.Select);
x.Lazy(LazyRelation.Proxy);
x.Column("ServiceOfferingId");
x.ForeignKey("FK_BusinessServiceOffering_ServiceOfferingId");
}
);
Removing property fixed the exception issue but test kept failing. Looking into the inserted sql I see 'null' inserted for ServiceOfferingId instead of assigned int values like:
INSERT
INTO
BusinessServiceOffering
(BusinessId, IsEnabled, CreatedDate, CreatedByLoginId, ModifiedDate, ModifiedByLoginId, ServiceOfferingId, BusinessServiceOfferingId)
VALUES
(@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7);
@p0 = 200 [Type: Int32 (0)], @p1 = True [Type: Boolean (0)],
@p2 = 2/28/2013 6:11:25 PM [Type: DateTime (0)],
@p3 = 20 [Type: Int32 (0)], @p4 = 2/28/2013 6:11:25 PM [Type: DateTime (0)],
@p5 = 30 [Type: Int32 (0)], @p6 = **NULL** [Type: Int32 (0)], --->
@p7 = 5 [Type: Int32 (0)]
I tried adding a bag on the "one" side but doesn't seem to make any difference.
What am I missing? Note that I have integration tests with sql server that run fine with or without the property. However, simple Read tests with sql server fail to return any data for those fields where property is removed.
Seems like I need to map properly or it's a sqlite idiosyncrasy.
Please help.
Ok. Figured this one out myself and posting an answer for somebody else, should they get into same issue.