Mapped property can't be found...
i,
I might have found a bug but am unsure if it is a fluent bug or a nhibernate bug but the nhibernate guys are mean and scary so I try here first. For some reason mappings are generated for two properties but when they are accessed I get an exception saying they don't exist. I am NOT using the xml mapping below but they are generated every time I build i don't know any way to show you the real mappings.
<column name="deleted_at" not-null="false" />
</property>
<property name="DeletedBy" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="deleted_by" length="25" not-null="false" />
</property>
When the property is accessed I get the following exception:
could not resolve property: DeletedAt of: FakturaLight.Invoice
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: NHibernate.QueryException: could not resolve property: DeletedAt of: Invoice
Source Error:
Line 203: public void DeleteInvoice(int id)
Line 204: {
Line 205: var invoice = Work.CurrentSession.QueryOver()
Line 206: .Where(x => x.Id == id)
Line 207: .And(x => x.DeletedAt == null)
The actual class looks like:
[MetadataType(typeof (InvoiceMetadata))]
public class Invoice : EntityBase
{
private decimal _invoiceTotal;
private decimal _kmTotal;
private decimal _productTotal;
private decimal _workdayTotal;
public Invoice()
{
Products = new List<Product>();
Workdays = new List<Workday>();
}
public virtual DateTime? DeletedAt { get; set; }
public virtual string DeletedBy { get; set; }
public virtual DateTime StartDate { get; set; }
public virtual DateTime EndDate { get; set; }
public virtual string Period { get; set; }
public virtual string InvoicePrefix { get; set; }
public virtual int InvoiceNumber { get; set; }
public virtual int Km { get; set; }
public virtual decimal KmPrice { get; set; }
public virtual decimal HourPrice { get; set; }
public virtual short GST { get; set; }
public virtual bool Printed { get; set; }
public virtual int CustomerId { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<Product> Products { get; private set; }
public virtual ICollection<Workday> Workdays { get; private set; }
}
public class InvoiceMapping : ClassMap<Invoice>
{
public InvoiceMapping()
{
Id(x => x.Id)
.GeneratedBy.Identity()
.UniqueKey("ix_invoice_id_prefix_number");
Map(x => x.InvoiceNumber)
.UniqueKey("ix_invoice_id_prefix_number");
Map(x => x.InvoicePrefix)
.Not.Nullable()
.UniqueKey("ix_invoice_id_prefix_number");
Map(x => x.StartDate);
Map(x => x.EndDate);
Map(x => x.Period);
Map(x => x.Km);
Map(x => x.KmPrice);
Map(x => x.HourPrice);
Map(x => x.GST);
Map(x => x.CustomerId);
Map(x => x.Printed);
References(x => x.Company)
.Column("company_id");
HasMany(x => x.Workdays)
.KeyColumn("invoice_id");
HasMany(x => x.Products)
.KeyColumn("invoice_id");
Map(x => x.CreatedAt)
.Nullable();
Map(x => x.CreatedBy)
.Nullable()
.Length(25);
Map(x => x.UpdatedAt)
.Nullable();
Map(x => x.UpdatedBy)
.Nullable()
.Length(25);
Map(x => x.DeletedAt)
.Nullable();
Map(x => x.DeletedBy)
.Column("deleted_by")
.Nullable()
.Length(25);
}
}
I can't spot anything wrong but when I try to generate schema (both for update and drop/export) it doesn't generate those two columns. I am clueless...
2 Posted by mikael on 14 Aug, 2010 11:34 AM
Ok, this is definitely a fluent nhibernate issue. Fluent NHibernate generates the mappings for the columns but they are not passed on to NHibernate. When I run with log4net level ALL for logger NHibernate I get the following:
< hibernate - mapping xmlns = "urn:nhibernate-mapping-2.2" default - access = "property" auto - import = "true" default - cascade = "none" default - lazy = "true">
So there is some issue here :(
3 Posted by mikael on 14 Aug, 2010 11:39 AM
The following is also logged. I have no friggin idea why this happens. Could someone please enlighten me?
Could it be .NET that is caching a previous version somewhere? I deleted the bin/obj folders and cleaned the tmp. Ran a build with clean and then a rebuild. But maybe I need to clean something else?
4 Posted by mikael on 14 Aug, 2010 02:35 PM
Ok guys you have a bug to take care of! :) I am currently running in XML mode...
The thing is that the mappings are outputted to disk ok (ExportTo(path)) but they are not sent to nhibernate ok. DeletedAt / DeletedBy are missing.
Support Staff 5 Posted by James Gregory on 14 Aug, 2010 05:26 PM
Mikael, thanks for the investion/report. I'm away from the computer right now, but I'll take a look the next chance I get.
6 Posted by mikael on 14 Aug, 2010 06:33 PM
Happy birthday mate!
Was not expecting a reply since it's your quarter of a century day :)
Mikael Henriksson
Tel: +46 (0) 730- 393 200
***@zoolutions.se
On Sat, Aug 14, 2010 at 7:28 PM, James Gregory <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
7 Posted by mikael on 30 Aug, 2010 06:26 PM
Don't want to be a bother but any news on this?
I had to skip fluent and use xml!
Support Staff 8 Posted by Paul Batum on 25 Sep, 2010 10:54 PM
Hi Mikael,
I am catching up on my much neglected pile of FNH related emails. Did you
find a resolution for this at all? Are you still using an xml file? Also, if
you are still on a xml file, are you using a hand written xml file? Did you
try exporting the FNH xml file and using that?
Paul.
On Mon, Aug 30, 2010 at 1:28 PM, mikael <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
9 Posted by mikael on 26 Sep, 2010 02:16 PM
Hi,
I still have that issue and am still using XML. As I think I stated
somewhere the XML generated to disk works but the actual in memory version
seems to be missing the property. Since I had to convert to xml I got rid of
all the unneeded stuff that FNH generates but it's pretty much the same
file.
Mikael Henriksson
Tel: +46 (0) 730- 393 200
***@zoolutions.se
On Sun, Sep 26, 2010 at 12:56 AM, Paul Batum <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
Support Staff 10 Posted by Paul Batum on 26 Sep, 2010 03:17 PM
Hi Mikael,
I've had another look at the code and I just can't see anything that might
be causing us to drop some properties from the xml. If its written to disk,
it really should be passed to NH. If you have built FNH from source you
could stick breakpoints on lines 279 and 288 of PersistenceModel.cs as this
is where we add the mapping documents to NH, and then you could check the
xml right before its passed in. Assuming the properties are in that XML, the
question will be why NH is ignoring them...
Paul.
On Sun, Sep 26, 2010 at 9:18 AM, mikael <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote: