I have the next entity:
public class Topic : EntityBase
{
private readonly ICollection<Vote> _votes;
public virtual string Title { get; protected set; }
public virtual ICollection<Vote> Votes
{
get { return _votes; }
}
public virtual int VotedUpCount
{
get
{
return _votes.Count(v => v.VotedTo == VoteType.VoteUp);
}
}
}
I need to map my VotedUpCount
(because I have an error from NH). BUT I don't need this property as column in my database.
I tried this one and got an error Invalid column name 'VotedUpCount'.
public class TopicMap : ClassMap<Topic>
{
public TopicMap()
{
Id(x => x.Id);
Map(x => x.Title);
Map(x => x.VotedUpCount).Access.ReadOnly();
HasMany<Vote>(x => x.Votes)
.Cascade.All();
}
}
Is there any way to map readonly properties using fluent interface to make this entity working?
Why do you want to map it? It's just a .NET property executing some code (that could also be a method) and has nothing to do with the database, just don't map it at all.
If you need a real DB property (where the value comes from a DB column) mapped as readonly:
Map(x => x.PropertyName).Column("ColumnName").ReadOnly();
// Alternative (does exactly the same, but is more like the NHibernate mapping:
Map(x => x.PropertyName).Column("ColumnName").Not.Insert().Not.Update();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With