fluent-nhibernate

Why nhibernate 3.3 doesn't allow private setter on ICollection?

点点圈 提交于 2019-12-05 18:53:19
I upgraded form nhibernate 3.2 to nhibernate 3.3, and I had a lot of virtual members defined in my domain classes like this: public virtual ICollection<Movie> Movies { get; private set; } This stopped working after the upgrade and I get this exception: Following types may not be used as proxies: ClassName: method set_Movies should be 'public/protected virtual' or 'protected internal virtual' Now I managed to solve the problem by changing the setter to protected but I was surprised also that changing the Collection property to be readonly with a backing field does the trick. So I have two

Fluent NHibernate ignore property inside the ClassMap, using FluentMappings

风流意气都作罢 提交于 2019-12-05 18:31:04
I am using NHibernate 3.1 and Fluent NHibernate as ORM in my project. I need to have a property of a POCO ignored by Fluent NHibernate. At first, my post might look as exact duplicate of this question , but it is not. My complications come first from the fact that the POCOs are defined in a different assembly than the mapping and I am using fluent mappings for my POCOs. I have additional requirement not to write ingore-property code where the session factory configuration takes place (this happens at a centralized place outside the modules), but as part of the module that defines the mappings.

Use of TransactionScope with read uncommitted - is with (nolock) in SQL necessary?

♀尐吖头ヾ 提交于 2019-12-05 17:36:45
问题 I am using FluentNHibernate, and I have a list of records, mapped to an SQL Server 2008 view. Dirty reads are OK with me, not locking the tables is a priority. The SQL Query inside the view, does not have any with (nolock), however, I am using the following approach... using (var txScope = new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { ... The reading of records from the view is done

Using MyGeneration with Fluent NHibernate

旧街凉风 提交于 2019-12-05 17:14:34
I found a fantastic template for NHibernate code generation using MyGeneration here, http://vucetica.blogspot.com/2009/01/nhibernate-template-for-mygeneration.html This creates XML mapping files with the extension hbm.xml. I was wonder if anybody knows of templates which support fluent NHibernate which defines the mapping using C# files. Thanks When you are using Fluent NHiberate you needn't hbm files, you can generate them based on your domain model and conventions 来源: https://stackoverflow.com/questions/1683663/using-mygeneration-with-fluent-nhibernate

Working with Time Type in Fluent Nhibernate generates exception “Unable to cast object of type 'System.DateTime' to type 'NHibernate.Type.TimeType”

断了今生、忘了曾经 提交于 2019-12-05 16:29:39
I founded that NHibernate have several builtin Types that are not present in C# , but are present in some of SGBD. Now I have following: public class TimeSlot : EntityBase { public virtual NHibernate.Type.TimeType FromTime { get; set; } public virtual NHibernate.Type.TimeType ToTime { get; set; } } public class TimeSlotMap : ClassMap<TimeSlot> { public TimeSlotMap() { Id(c => c.Id).GeneratedBy.Identity(); Map(c => c.FromTime); Map(c => c.ToTime); } } In MSSQL this table look like in attached image Now when I am trying to query this table I am getting following exception: Unable to cast object

Using discriminator with Fluent NHibernate

我与影子孤独终老i 提交于 2019-12-05 16:25:18
I'm trying to create a discriminator column. This column would hold one of the many statuses available. Like my code will show each status has a name as well as a background color. Each status share the same base class. Here is my code: public class Item { public virtual int Id { get; set; } public virtual Status ItemStatus { get; set; } } public abstract class Status { private readonly int _id; public static readonly Status Foo = new FooStatus(1); public static readonly Status Bar = new BarStatus(2); public Status() { } protected Status(int id) { _id = id; } public virtual int Id { get {

Fluent NHibernate error: The entity 'ClassMap`1' doesn't have an Id mapped

一世执手 提交于 2019-12-05 14:25:34
I'm converting a previous project from using normal NHibernate hbm.xml mappings to Fluent NHibernate. Currently, I'm stuck on what should be one of the last steps to getting this working. I've added a derived class for DefaultAutomappingConfiguration to modify my ID naming convention. The string "Id" is appended to the class name: public override bool IsId(FluentNHibernate.Member member) { return member.Name == member.DeclaringType.Name + "Id"; } This should make "Agency" have an ID in a field named "AgencyId". Instead, I'm getting this error: The entity 'ClassMap`1' doesn't have an Id mapped.

Fluent NHibernate: Prevent class from being mapped

前提是你 提交于 2019-12-05 13:40:45
I am sure it is a piece of cake, but I can't find it using google. I need to EXCLUDE a single class from mapping. My current configuration is: return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(@"Data Source=PC\SQLEXPRESS;......"))) .Mappings(m => m.AutoMappings.Add( AutoPersistenceModel.MapEntitiesFromAssemblyOf<Person2>() .Where(t => t.Namespace == "ExampleData.HumansTest") .UseOverridesFromAssemblyOf<PersonMappingOverrides>() .ConventionDiscovery.AddFromAssemblyOf<PersonMappingOverrides>() ) ).BuildConfiguration(); Works nice, so far... But I have

Extend/Modify NHibernate classes at runtime

二次信任 提交于 2019-12-05 13:32:52
Apologies if there's an on point answer already out there but I haven't found it. I'm using NH3 and I've got a use case where I want to add a Set onto any entity who's class implements a specific interface. I have a configuration builder class so I can make these changes before creating the session factory. Given this reduced example: public class Person : IHasExtraItems { public Person() { this.ExtraItems = new HashSet<ExtraItem>(); } public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual DateTime Birthdate { get; set; } public virtual ICollection

NHibernate exception: could not initialize a collection, Invalid column name. Fluent mapping. Maybe a many-to-one issue?

馋奶兔 提交于 2019-12-05 12:42:45
I am puzzled and frustrated by an exception I'm getting via NHibernate. I apologize for the length of this post, but I've tried to include an appropriate level of detail to explain the issue well enough to get some help! Here's the facts: I have a Person class which contains a property BillingManager , which is also a Person type. I map this as an FNH "Reference". I have an ExpenseReport class which contains a property SubmittedBy , which is a Person type. I map this as an FNH "Reference". I have a BillableTime class which contains a property Person , which is a Person type. I map this as an