fluent-nhibernate

Enum parsing doesn't seem to work with Fluent NHibernate

余生颓废 提交于 2019-12-08 14:47:09
问题 I have a data access class with an Enum called Salutation: public enum Salutation { Unknown = 0, Dame = 1, etc Mr = 5, etc } I am peristing the class with NHibernate, and up until this morning I was using .hbm.xml files for mapping. However, I've now switched to using Fluent NHibernate, but loading instances of the class fails with (for example): [HibernateException: Can't Parse 5 as Salutation] As you can see, 5 should be parseable as a Salutation (assuming 5 is an int, it's not possible to

FluentNHibernate: How to map database char to c# bool?

自古美人都是妖i 提交于 2019-12-08 13:23:18
问题 I have set up my first project using FluentNHibernate. When I tried to get a list of records from a single table, I got an exception which says: System.FormatException : String was not recognized as a valid Boolean. The problem is that in the database table, there is a column called "flag" and its data type is char, but it only contains values of either '0' or '1'. So, I'd like to map it to type bool in my POCO: public class Students { public virtual int Id {get; private set;} public virtual

Fluent NHibernate, questions about code design

拟墨画扇 提交于 2019-12-08 12:39:37
问题 Greeetings, i'm a new to Fluent NHibernate. Let's imagine, a have a lot of classes ClassA ClassB ClassC ... After creating schema, i want to get a list of created tables. For example: Opening form -> there's a names of the Tables, when we clicking to each one we're getting records from this table. How can I achieve this? Is there a cheaper way? Is it possible to make without reflection? (Parsing all classes, and gettings it's names) 回答1: NHiberante has built-in support to get names of all

Fluent NHibernate Mapping not on PK Field

淺唱寂寞╮ 提交于 2019-12-08 10:48:47
问题 I have the following tables and cannot edit their structure... Person ------ Id PK Code Name Order ----- Id PK Person_Code OrderDetails Now in my Person class I want to have a list of Orders for that person, but I'm not entirely sure how to go about setting up the mapping in fluent nhibernate to match on the Code column rather than the ID. There is no foreign key constraint and I am unable to change the database to use the keys. Something like this is what I require, but can;t seem to figure

Rename NHibernate criteria

北慕城南 提交于 2019-12-08 09:12:41
问题 I am trying to join aliases multiple times but it depends on the number of times it should do it. Employee employeeAlias = null; Thing thingAlias = null; var names = string[] {"A", "B", "C", "D", "E"} // number of values could vary for(int i = 0; i < names.Length ; i++) { queryOver .JoinAlias(() => employeeAlias.Things, () => thingAlias, JoinType.LeftOuterJoin, Restrictions.Eq(Projections.Property(() => thingAlias.Name, names[i])); } However, upon execution, NHibernate throws an error saying:

NHibernate: Default value for a property over a null column

余生颓废 提交于 2019-12-08 08:45:33
问题 I'm working with an old database used by other applications, so i can't modify its structure. Sometimes i have nullable columns that i want to map as a non nullable type. For instance I have a nullable EndValidity column on database which i want to map on a non nullable DateTime, and, if null, it should be DateTime.MaxValue, or as a more simple example, a nullable bit column that must be false if null. I'm thinking about writing a custom user type for it (with parameters if possible), or is

Fluent NHibernate Newbie: Row was updated or deleted by another transaction

我怕爱的太早我们不能终老 提交于 2019-12-08 08:19:49
问题 I'm in the early stages of building out a database with Fluent NHibernate. I implemented a unit-of-work pattern in ASP.NET MVC 3 to let NHibernate update my database schema for me. To insert/update my initial data, I have a Database controller with an Update action that tries to SaveOrUpdate(...) a User entity (the administrator user) into the Users table. After manually deleting all user records via Visual Studio and re-running my Update action to repopulate the Users table, I receive the

Unwanted NHibernate update command

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 07:57:57
问题 I have the following classes public class Contact { public Contact() { Addresses = new List<Address>(); EmailAddresses = new List<EmailAddress>(); PhoneNumbers = new List<PhoneNumber>(); } public virtual int ContactID { get; private set; } public virtual Firm Firm { get; set; } public virtual ContactType ContactType { get; set; } public virtual string FullName { get; set; } public virtual string FiscalCode { get; set; } public virtual string Notes { get; set; } public virtual ContactRole

Cascade insert on one-to-many with fluent NHibernate

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 06:27:49
问题 I have two classes mapped using fluent NHibernate - User and a UserRoleAssignment. An User has many UserRoleAssignments. Here's the relevant map for user: HasMany(x => x.Roles) .Table("UserRoleMap") .Cascade.SaveUpdate(); And for UserRoleAssignment: Map(x => x.User_Id); As you can see, I'm only referencing from User to UserRoleAssignment. From UserRoleAssignment, I'm only mapping the foreign key column (User_Id). The problem is, that when I save the user, I get an exception caused by the

Reference parent table alias in Fluent NHibernate ClassMap Formula?

最后都变了- 提交于 2019-12-08 05:44:12
问题 Is it possible to reference or rename an entity's table alias in a Fluent NHibernate Formula? I can usually use "this_" but that unfortunately does not seem to be consistent based on the number of other aliases NHibernate generates. this.Map(x => x.IsLocked).Formula("CASE WHEN (SELECT COUNT(*) FROM dbo.Child c WHERE c.InboundDate >= BeginDate AND c.InboundDate < EndDate) > 0 THEN 1 ELSE 0 END"); This gets me by but I run into trouble when I need to match of identically named fields, (like "ID