nhibernate

NHibernate mapping problem - Could not initialize proxy - no Session

拈花ヽ惹草 提交于 2019-12-31 05:25:12
问题 I have just started to learn NHibernate, and are following tutorials. On my own learning project, I have made up a problem for myself. I have two tables: Team: TeamId* Name Match: MatchId* TeamAId TeamBId The model entities are: Team public virtual int? TeamId { get; private set; } public virtual string Name { get; set; } public virtual IList<Match> HomeMatches { get; set; } public virtual IList<Match> AwayMatches { get; set; } Match public virtual int? MatchId { get; private set; } public

Fluent Nhibernate problem

坚强是说给别人听的谎言 提交于 2019-12-31 04:58:07
问题 I have this in my entity: public virtual Iesi.Collections.Generic.ISet<long> Blas { get; set; } and this for my mapping: mapping.HasMany(x => x.Blas).AsSet().Element("Value", m => m.Type<long>()); This creates the relevant tables and I add data like this: X.Blas = new Iesi.Collections.Generic.HashedSet<long>(); X.Blas.Add(some_long); This adds values to the object but the values in Blas are never persisted (everything else of X is). Can anyone see anything wrong? Thanks. Christian 回答1: if X

Finding the Primary Key from a ClassMap<T>

前提是你 提交于 2019-12-31 03:56:29
问题 With Fluent NHibernate , I have an arbitrary ClassMap<T> , I want to be able to find out what property (if any) was set as the primary key . Example: public class PersonMap : ClassMap<Person> { public PersonMap() { Id(p => p.StupidPrimaryKeyId).GeneratedBy.Identity().Column("StupidPrimaryKeyId"); } } ... //usage MemberInfo primaryKeyMember = FindPrimaryKey(new PersonMap()); Can anybody tell me what the method body for FindPrimaryKey would have to be in order to return StupidPrimaryKeyId ?

Nhibernate Linq query to QueryOver

落爺英雄遲暮 提交于 2019-12-31 03:44:04
问题 I have the following piece of code: 1: ids = GetAnArrayOfIds(); 2: jobEntities = jobEntities.Where(j => j.Locations.Select(l => l.Id).Any(ids.Contains)); How do I write 2 using QueryOver ? Thank you, 回答1: var results = session.QueryOver<Job>() .JoinQueryOver<Location>(u => u.Locations) .Where(loc => loc.Id.IsIn(ids)) .TransformUsing(Transformers.DistinctRootEntity) .List(); Hope this helps 来源: https://stackoverflow.com/questions/6997146/nhibernate-linq-query-to-queryover

How to change default FlushMode to Commit in C#?

北慕城南 提交于 2019-12-31 03:18:14
问题 So... already said it: How to change FlushMode to Commit in C#? I mean, In Fluent NHibernate FlushMode by default is setted as Auto. So... to set FluentMode to Commit , I need to open session and then change It: var someSessionFactory = ... bla bla ..; var session = someSessionFactory.OpenSession(); session.FlushMode = FlushMode.Commit; This will work but... this will mean that I need to call method which contains FlushMode.Commit each time I am opening session. To inicialize sessionFactory I

How to configure NHIbernate event listeners for Update and Save?

巧了我就是萌 提交于 2019-12-31 03:07:11
问题 Following on from my previous question How to implement LastUpdate in NHibernate Entities?. I have two columns on my audited tables in my database: created datetime default getdate() not null (the creation date of this row) lastUpdate datetime null (the datetime this row was last updated) I want to create a listener for updates only in NHibernate, because the database engine takes care of new records with the default constraint. I tried to create a Custom listener with this code: public class

Testing Connection Parameters with NHibernate

六月ゝ 毕业季﹏ 提交于 2019-12-31 02:53:06
问题 We have a program where users can specify their database connection parameters. The usual suspects including host, port, username, password, and table name. We are connecting to the database using NHibernate. What we'd like to do is be able to build the configuration with NHibernate and then test the connection parameters before continuing with other operations; notifying the user of failure. Is this possible to do through NHibernate, or will it require using each database type we support's

Exclude property from INSERT command in nhibernate

笑着哭i 提交于 2019-12-31 02:28:12
问题 I have an entity with a property which I wish to be readonly - meaning that when I insert this entity to the DB, SqlServer will generate the property's value automatically so I need nhibernate to ignore this property when executing the INSERT command but retrieve it when selecting the entity. Important note: this property isn't ID ! I don't want NHibernate to initialize it using generator, SqlServer will do it by itself. And another note: I use configuration mapping so no fluent mapping

FluentNHibernate query on many-to-many relationship objects

妖精的绣舞 提交于 2019-12-31 02:20:09
问题 For some reason i can't get this query right, and i can't understand why... I have an object called 'Blog' that has an Id, and a list of 'Tag's. Each 'Tag' has an id and a 'Name' property. Since this is a many to many relationship, I have another table called 'blog_tags' connecting them. The mappings look like this : public class BlogsMapping : ClassMap<Blog> { Table("blogs"); Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Content); HasManyToMany(x => x.Tags) .Table("Blog_Tags")

NHibernate and database connection failover?

天涯浪子 提交于 2019-12-31 02:19:15
问题 I am using NHibernate to connect to a legacy rdbms system. Under high production load the rdbms service fails. To maintain the availability we have a failover rdbms service. Is there a way to configure NHibernate to use the FailOver Connection String when the primary connection is down? Additional Info: I am using Castle over NHibernate. If Castle provides handling of failover connections then that will also do it for me. 回答1: You can build your own NHibernate.Connection.IConnectionProvider