nhibernate

NHibernate - join without mapping

匆匆过客 提交于 2020-01-03 19:18:32
问题 Is it possible to join two classes without specified mapping between them (using Criteria API)? I must join two classes and retrieve data from both but I can't mapping them. I know only foreign key SomeID in the first class and primary key ID in second. How to create Criteria to join them? Is it possible without mapping? Please, help, I'm really need it but I'm stuck. :/ PS I know 'any' mapping but I have 10 fields like SomeID. Creating any mappings for 10 fields only for creating joins is

Readonly collection properties that NHibernate can work with

孤街醉人 提交于 2020-01-03 18:51:48
问题 My domain classes have collections that look like this: private List<Foo> _foos = new List<Foo>(); public virtual ReadOnlyCollection<Foo> Foos { get { return _foos.AsReadOnly(); } } This gives me readonly collections that can be modified from within the class (i.e. by using the field _foos). This collection is mapped as follows (Fluent NHibernate): HasMany(x => x.Foos).KeyColumn("ParentClassId").Cascade.All().Inverse().Access.CamelCaseField(Prefix.Underscore); Now when I try to use this

How to increment ID before any insert with NHibernate

半腔热情 提交于 2020-01-03 18:42:17
问题 It looks like NH gets MAX(ID) only once, at first insert and then stores this value internally, this causes me some problems when other processes inserts data. Then I have not actual ID and duplicate key exception is thrown. Lets imagine we have table Cats CREATE TABLE Cats(ID int, Name varchar(25)) Then we have corresponding mapping done with FluentNhibernate public class CatMap : ClassMap<Cat> { public CatMap() { Id(m=>m.ID).GeneratedBy.Increment(); Map(m=>.Name); } } All I want to achieve

Would nhibernate be used in large scale projects like say facebook? (for arguments sake)

夙愿已清 提交于 2020-01-03 17:31:31
问题 For those who know the inner workings of nhibernate, do you think a large scale web application like say facebook/myspace would use nhibernate? Or is nhibernate well suited for more low traffic sites like company sites etc? i.e. not enterprise ready because of its chatty nature? 回答1: NHibernate is not chatty at all. About scalability, there was already a question on NH's groups, which was more about the complexity of the database then traffic, but might still be interesting for you. Even if

Can an ICriteria return an IDictionary instead of a List<DTO>?

不问归期 提交于 2020-01-03 17:20:30
问题 Currently I can get this SetResultTransformer method to return a List of some arbitrary kind of DTO as follows: var result = _session.CreateCriteria<Company>() .Add(Restrictions.In(groupCompanyInfo, (int[])groups.Select(xx => xx.Id).ToArray())) .SetProjection(Projections.ProjectionList() .Add(Projections.GroupProperty(groupCompanyInfo), "CompanyInfoGroupID") .Add(Projections.RowCount(), "TotalNumberOfCompanies")) .SetResultTransformer(Transformers.AliasToBean<SomeDTO>()) .List<SomeDTO>();

Execute a custom query in nhibernate and map to a custom domain object

北慕城南 提交于 2020-01-03 15:17:08
问题 Hi i have a query like this SELECT Customer.Name, sum([Load].Profit) as Profit FROM Customer INNER JOIN [Load] ON Customer.Id = [Load].CustomerId GROUP BY Customer.Name I need to execute this query in nhibernate and map it to a Custom domain object which i created as like this public class CustomerProfit { public String Name; public Decimal Profit; } Is it possible to do so ? and how , or is it possible to execute this custom query in HQL ? 回答1: public sealed class CustomerProfitQuery :

nHibernate enumerating the same collection on multiple threads

自作多情 提交于 2020-01-03 13:20:56
问题 I have a production application (IIS8, MVC5, nHibernate DAL) and I'm noticing high CPU usage as of late. Cycling the app pool fixes it but after doing some diagnostics and memory dumps from the server to analyze the issue, I noticed a consistent pattern of multiple threads trying to enumerate the same collection. The most common point is where the app checks the roles of the user. I suspect this might be more do to the fact that this code is ran for every request to verify permissions, so it

NHibernate: proxies cannot be fetched by a stateless session error message

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 13:20:06
问题 I'm using an nHibernate stateless session to fetch an object, update one property and save the object back to the database. I keep getting the error message: proxies cannot be fetched by a stateless session I have similar code working elsewhere, so I can't figure out why this isn't working. Does anyone have any idea what the problem might be? I'm trying to update the ScreenLockVersion property. Mapping: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2

NHibernate: Get concrete type of referenced abstract entity

南笙酒味 提交于 2020-01-03 10:57:34
问题 I have the following classes: public abstract class FooBase { public virtual Guid Id { get; set; } } public class FooTypeA : FooBase { public virtual string TypeAStuff { get; set; } } public class Bar { public virtual Guid Id { get; set; } public virtual FooBase Foo { get; } } FooBase and FooTypeA are mapped using the table-per-class-heirarchy pattern. Bar is mapped like this: public class BarDbMap : ClassMap<Bar> { public BarDbMap() { Id(x => x.Id); References(x => x.Foo) .LazyLoad(); } } So

Receiving Index Out of Range with NHibernate

孤人 提交于 2020-01-03 10:44:19
问题 I'm hoping that someone can help me with this issue. I've been racking my brain and my project is due very soon. Thank You in advance. I'm receiving an index out of range exception when inserting a new record. After searching endlessly for information, it was suggested that the number of column values in my mapping do not match that in my persistent class. However, I counted and re-counted, and they seem to match. As you can see by my code below, I'm using NHibernate.Mapping.Attributes to do