fluent-nhibernate-mapping

Fluent NHibernate 3 table relation without primary and foreign keys

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:54:31
问题 Background Info I have the following class that I want to map with NHibernate: public class Player { public virtual int Id { get; set; } public virtual Type Type { get; set; } public virtual string ScreenName { get; set; } public virtual bool Unsubscribed { get; set; } } On the database side, I have the following tables: -- New table Player ( int Id int TypeId (not null) -- foreign-key to Type table string ScreenName (not null) -- can be an EmailAddress, but not necessarily ) Type ( int Id

Fluent Nhibernate loading not falling back on lazy loading? (grandchild entities)

不打扰是莪最后的温柔 提交于 2019-12-12 04:18:27
问题 When querying nhibernate, I'm seeing some odd behavior When I write a query like this Repository.QueryOver<Entity>() .Fetch(x => x.Child1).Eager .Fetch(x => x.child2).Eager It will eagerly grab child1 and child2 entities, but there are grandchildren for child1 and child2 that aren't lazily loaded. I'm a bit confused on how to achieve this. In my nhibernate mappings, it seems to have no affect on the laziness or eagerness of grandchildren and I require at least some entities be eagerly loaded

Storing an object[] as column in Fluent NHibernate

孤街醉人 提交于 2019-12-12 01:07:59
问题 I have the following (partial) model: class LogMessage{ string Format; object[] args; } I want to store args[] as a single column in the table, taking advance of the fact that format arguments are generally serializable or can be converted to a string a priori . I don't want to store the formatted message, I want to separately store format and args (this has several advantages). How can I tell Fluent NHibernate to use a BLOB type to store that column and perform simple binary serialization

nHibernate - Populate a mapped function with namedQuery

时光总嘲笑我的痴心妄想 提交于 2019-12-12 01:02:17
问题 I'm using Fluent nHibernate for my data layer, and I have a class that is mostly populated through nHibernate/LINQ but in a few advanced usages, needs to be populated by a stored procedure. The problem I have is the class mapping includes a Formula. When I call a nHibernate/LINQ function, the underlying variable is populated as expected; when I call the GetNamedQuery() function it throws an error: Value cannot be null. Parameter name: fieldname It's completely logical that for a NamedQuery ,

how to keep many to many relationships in sync with nhibernate?

独自空忆成欢 提交于 2019-12-11 14:36:54
问题 I am creating data model for two objects Employee and Department. Employee has a list of departments and Department has a list of employees. class Employee{ private IList<Department> _departments; public Employee() { _departments = new List<Department>(); } public virtual ReadOnlyCollection<Department> Departments{ get {return new ReadOnlyCollection<Department>(_departments);} } } class Department{ private IList<Employee> _employees; public Department() { _departments = new List<Employee>();

NHibernate.MappingException : No persister for: System.Int32

陌路散爱 提交于 2019-12-11 09:50:31
问题 I have the following... public class TempCartMap : ClassMap<TempCart> { Id(x => x.Id).GeneratedBy.Identity(); ... HasMany(x => x.Products) .Inverse().Cascade.AllDeleteOrphan() .Table("tblCartProducts") .Element("ProductId").KeyColumn("CartId").AsBag(); } [Serializable] public class TempCart { public TempCart(){ Products = new List<int>(); } public virtual IList<int> Products { get; set; } } And a persistance specification: [Test] public void CanMapSaleCart() { SystemTime.Freeze(); IList<int>

NHibernate - Unable to save child entities

别等时光非礼了梦想. 提交于 2019-12-11 06:18:54
问题 This is supposed to be a simple 1-N relationship, however I am not able to save the children as NHibernate uses null as a value in the insert statement of the child. public class Event { public virtual string Id { get; set; } public virtual string Name { get; set; } public virtual IList<EventParameter> Parameters{ get; set; } public Event() { Parameters = new List<EventParameter>(); } } [Serializable] public class EventParameter : Parameter { public virtual Event Event { get; set; } public

Fluent NHibernate - HasOne With Where Clause

混江龙づ霸主 提交于 2019-12-11 05:47:34
问题 with Fluent NHibernate i can map a one to many relationship against my User class by saying: HasMany(x => x.Membership) .KeyColumn("UserID") .Where("Deleted = 0"); This works as expected that it only grabs the Membership records which have not been deleted. No say i have a field called Latest against the Membership where i know this would return one record per user, i'd like to be able to say: HasOne(x => x.CurrentMembership) .Where("Current = 1"); But there is no Where method. I know i could

Mapping Geometry from SQLServer2008 to .NET (NHibernate 4.0.0.4000)

那年仲夏 提交于 2019-12-11 04:01:37
问题 I try to map a SqlServer2008 geometry with FluentNHibernate. I am using NHibernate version 4.0.0.4000. I installed NHibernate.Spatial, NetTopologySuite, GeoAPI and NHibernate with FluentNhibernate all with NUget. My Fluent mapping looks like this: public class ArealMap: ClassMap<Areal> { public Areal() { Table("Areal"); Id(x => x.Id).Column("Id").GeneratedBy.Identity(); Map(x => x.Geometry).Column("Geometry").CustomType(typeof(MsSql2008GeometryType)); } } public class Areal { .... public

How to fill just required properties of entity (FluentNHibernate)

て烟熏妆下的殇ゞ 提交于 2019-12-11 03:29:12
问题 I am using FluentNHibernate to access to my database. I would like to implement next - just required properties of my entity should be filled. By example, in one case all properties should be filled, in second case repository should return entity with ID and Name properties only. Does it make sence? I see point when I can implement a few mappings for entity - every mapping according to case. Then I get a few ISessionFactory'ies - repository uses required ISessionFactory to cover required case