mapping-by-code

Using NHibernate mapping by code: Cannot insert explicit value for identity column in table 'DietUser' when IDENTITY_INSERT is set to OFF

◇◆丶佛笑我妖孽 提交于 2019-12-10 13:44:55
问题 Took me a while to find an answer for this so thought I'd share the love. When using NHibernate's new mapping by code with SQL Server I'm unable to save an entity. When saving an entity a System.Data.SqlClient.SqlException is thrown with the following message (minus the table name): "Cannot insert explicit value for identity column in table 'DietUser' when IDENTITY_INSERT is set to OFF." My table uses an identity ID and the entity & mappings look like this: public class User { public virtual

nhibernate : read write list of string

青春壹個敷衍的年華 提交于 2019-12-10 10:57:16
问题 I know I can read write list of string like below using nhibernate HasMany(x => x.Attachments) .KeyColumn("RowId") .Table("PostTable").Element("PostKey"); But this creates an extra table, is there a way e.g. UserType or something else, so that we can directly write to list... if yes any example of custom UserType using nhibernate?? with sample code... I also want that If i add value to list that also should be saved. I have seen below example code which breaks in case we add value to list...

How would I join a table on a non primary key field using NHibernate Mapping.ByCode?

心已入冬 提交于 2019-12-10 10:32:21
问题 I have an employee table: Employee { Name EmployeeId -pk PositionId -fk } The positionId maps to the position table: Position { PositionId -pk ReportsToId PositionName PositionDescription } The ReportsToId field is a position Id for that positions manager. I would like to select out an employee, their position and their managers details. How would this be done using NHibernate's Mapping.ByCode. The ReportsToId field is not a key field. From what I've read online, this seems to affect the

Using a Property mapping with a Formula in NHIbernate

萝らか妹 提交于 2019-12-08 16:58:54
问题 I am trying to map a property to an arbitrary column of another table. The docs say that the formula can be arbitrary SQL and the examples I see show similar. However, the SQL NHibernate generates is not even valid. The entire SQL statement from the formula is being injected into the middle of the SELECT statement. Property(x => x.Content, map => { map.Column("Content"); map.Formula("select 'simple stuff' as 'Content'"); }); 回答1: This is the way Formula is designed, it is supposed to work

database column to constant value without the need for a property in the entity class with mapping by code

柔情痞子 提交于 2019-12-08 04:41:20
问题 this is almost the same as this question except using NH's mapping-by-code. I really need the virtual properties because i also want to use SchemaExport to create the database for different rdbms without the need to create/maintain scripts for each. Maybe there is a MbC Guru who knows how to do it with MbC Update: the obvious simple code Property("dummyProperty", c => { c.Column("legacyColumn"); c.Access(typeof(MyPropertyAccessor)); }); does not work NHibernate.MappingException: Unable to

NHibernate - Force escaping on Table Names

别来无恙 提交于 2019-12-07 03:05:40
问题 Are there any good examples of how to use this (NHibernate.Criterion.IdentifierEqExpression) online? I couldn't find any. I'm a little confused about what you are supposed to pass into the constructor. I pass in an int32 of 1 and I keep thinking my test should basically do a "where id = 1" type of query and instead it blows up with "where id = ?" and something about positional parameters. If that's not what is supposed to be passed into the constructor ... what is? Real Issue When I look at

NHibernate mapping by code: How to map IDictionary?

假装没事ソ 提交于 2019-12-06 07:52:34
How can I map these Entities using mapping-by-code: public class Foo { public virtual IDictionary<Bar, string> Bars { get; set; } } public class Bar { public virtual int Id { get; set; } public virtual string Name { get; set; } } I found this thread , but it does not map an entity, only simple types. I tried many mappings, including automapping: Map(x => x.Bars, m => { m.Key(k => k.NotNullable(true)); m.Cascade(Cascade.All); }, But most of them throw these two errors: Foreign key (Bars [idx])) must have same number of columns as the referenced primary key (Bars [FooId, idx]). An association

nhibernate : read write list of string

余生长醉 提交于 2019-12-06 07:34:11
I know I can read write list of string like below using nhibernate HasMany(x => x.Attachments) .KeyColumn("RowId") .Table("PostTable").Element("PostKey"); But this creates an extra table, is there a way e.g. UserType or something else, so that we can directly write to list... if yes any example of custom UserType using nhibernate?? with sample code... I also want that If i add value to list that also should be saved. I have seen below example code which breaks in case we add value to list... private virtual string StringValue public virtual IList<string> valueList { get { return StringValue; }

Simple get using NHibernate (using mapping-by-code) is extremely slow

人盡茶涼 提交于 2019-12-06 01:19:27
So i've run out of ideas as to why this is so slow. Maybe you can help. So I am trying to do a simple get on record from an oracle db using nHibernate mapping by code. I'm using nHibernate verison 3.3.1.4 from nuget. Here is the mapping code: public class Person { public virtual PersonKey Key { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } public class PersonKey { public virtual string PersonId { get; set; } public override bool Equals(object obj) { if (obj == null) return false; var t = obj as PersonKey; if (t == null) return false;

NHibernate - Force escaping on Table Names

a 夏天 提交于 2019-12-05 08:38:54
Are there any good examples of how to use this (NHibernate.Criterion.IdentifierEqExpression) online? I couldn't find any. I'm a little confused about what you are supposed to pass into the constructor. I pass in an int32 of 1 and I keep thinking my test should basically do a "where id = 1" type of query and instead it blows up with "where id = ?" and something about positional parameters. If that's not what is supposed to be passed into the constructor ... what is? Real Issue When I look at SQL output it seems to be working correctly except for the fact my table is named User and NHibernate