nhibernate-mapping

NHibernate mapping error ([EntityName] not mapped)

时间秒杀一切 提交于 2019-12-25 00:03:31
问题 My project (c#, nhibernate, npgsql, nlog) has one entity named Entry and should be mapped to the database table named test . Table contains some test entries. My application code is as follows: public void work() { ISessionFactory sessions = new Configuration().Configure().BuildSessionFactory(); ISession session = sessions.OpenSession(); IList<Entry> entries = session.CreateQuery("from Entry").List<Entry>(); foreach (Entry e in entries) { logger.Debug("Entry: " + e.id + " with " + e.name); }

Map fields from two tables to create a single entity

江枫思渺然 提交于 2019-12-24 19:07:16
问题 I'm working on a feature to add the ability for each of our customers to define a customized registration form for their account and I've run into a bit of a roadblock in creating my Fluent NHibernate mapping for one of the objects. There are two tables involved [RegistrationField] and [AccountRegistrationField] . [RegistrationField] contains a static list of all of the fields that are available to pick from as well as some information on how to render the field (e.g. should it be a textbox,

Discriminator based on joined property

旧街凉风 提交于 2019-12-24 17:24:56
问题 Suppose I have this relationship: abstract class Base { int Id; int JoinedId; ... } class Joined { int Id; int Discriminator; ... } class Sub1 : Base { ... } class Sub2 : Base { ... } for the following tables: table Base ( Id int, JoinedId int, ... ) table Joined ( Id int, Discriminator int, ... ) I would like to set up a table-per-hierarchy inheritance mapping for the Base, Sub1, Sub2 relationships, but using the Disciminator property from the Joined class as the discriminator. Here's the

NHibernate MappingException. No Persister

大城市里の小女人 提交于 2019-12-24 14:17:09
问题 I'm trying to get NHibernate to work. I've got this class: mm.k.Domain.Kampagne (namespace/assembly is mm.k.Domain) In another Visual Studio project (Assembly mm.k.Infrastructure) I got my Mapping files (in a Mappings directory), my hibernate.cfg.xml and some repositories. Heres my mapping file: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="mm.k.Domain" namespace="mm.k.Domain"> <class name="Kampagne" table="Kampagner"> <id name="Id">

wont save to database with guid as id- fluent-nhiberate

不羁岁月 提交于 2019-12-24 11:56:23
问题 i got problems with saving when i use Guid as identifier. can anybody se what i am missing here? i create my own guid so i dont want it to be generated by database. NOTE: i have tried the guid.combo in mapping to without any success. public class Order { public virtual Guid Id { get; set; } public virtual ICollection<OrderItem> OrderItems { get; set; } public virtual User User { get; set; } public virtual DateTime? CreateDate { get; set; } public virtual DateTime? ShippedDate { get; set; }

How connect nhibernate to local SQLEXPRESS?

我只是一个虾纸丫 提交于 2019-12-24 10:27:16
问题 I have in project simple connection to database: public static string GetConnectionString() { return @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + HttpContext.Current.Request.PhysicalApplicationPath + "Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; } Now I try to implement NHibernate to project. hibernate.cfg.xml here: <?xml version="1.0" encoding="utf-8"?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name=

(Fluent) NHibernate: Map complete table to one object

橙三吉。 提交于 2019-12-24 07:25:26
问题 I have the following database table: Settings Key | Value ---------------|------------------- SomeSetting | Foo AnotherSetting | Bar ... | ... And want to map this to the following object: public class Settings { public virtual string SomeSetting { get; set; } public virtual string AnotherSetting { get; set; } } How could I accomplish this using (Fluent) NHibernate? 回答1: I would map the key/value pairs to a private IDictionary and expose the properties by accessing the dictionary. See Ayende

Escaping a question mark character in a column name in NHibernate

点点圈 提交于 2019-12-24 06:37:55
问题 I have an entity with a property whose column name contains a question mark. How do I map the column name so that an HQL query will correctly generate SQL with the column name wrapped appropriately (i.e. [] for SQL Server) instead of substituting a parameter for the question mark? I have tried wrapping the column name in backticks or square brackets but this doesn't work. 回答1: Backticks work fine for me. Remember to use them only in the mapping file, not in the HQL: <property name="Data1"

NHibernate Mapping multiple tables to one class

百般思念 提交于 2019-12-24 02:50:06
问题 In my legacy Database I have a situation like this: TableA (id_A[PK], cod_A) TableB (id_B[PK], cod_B, id_A[FK]) TableC (id_C[PK], cod_C, id_B[FK]) For several reasons I need to map these tables into a single class (Foo in this example) public class Foo { public virtual string IdA { get; set; } public virtual string CodA { get; set; } public virtual string IdB { get; set; } public virtual string CodB { get; set; } public virtual string IdC { get; set; } public virtual string CodC { get; set; }

Is it true that NHibernate ISession.save(newTransientEntity) will only return generated Id, but NOT updating the Id property of the entity?

安稳与你 提交于 2019-12-24 01:55:09
问题 Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA { ... [Id][Generator(class="guid")] public Guid Id {...} [Property] public string Property1 {...} ... } Let say if I add a transient entity to the persistence context with code like this: ... Guid id; using(ISession s = sessionFactory.OpenSession()) using(ITransaction t = s.BeginTransaction()) { EntityA entity = new EntityA(); entity.Property1 = "Some Value"; id = (Guid) s.Save(entity)