Search Results

Search found 3292 results on 132 pages for 'nhibernate statistics'.

Page 7/132 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Where clause in Fluent NHibernate Many-to-Many

    - by Adam Albrecht
    I am trying to setup a many-to-many mapping in Fluent Nhibernate that has a where clause attached to the child table. This is basically how it should work: HasManyToMany(p => p.Images) .Table("ProductImages") .ParentKeyColumn("ProductID") .ChildKeyColumn("ImageID") .Where("ImageTypeID = 2"); The ImageTypeID column is in the Images table, but NHibernate is assuming it is part of the ProductImages table. Any idea how I can specify this? Thanks!

    Read the article

  • NHibernate requires events to be virtual?

    - by Jimit
    I'm attempting to map an entity hierarchy using NHibernate almost all of which have events. When attempting to build a session factory however, I get error messages similar to the following: Core.Domain.Entities.Delivery: method remove_Scheduled should be virtual Delivery is an entity in my domain model with an event called Scheduled. Since events cannot be declared virtual I'm at a loss as to how to proceed here. Why would NHibernate need events to be virtual?

    Read the article

  • many-to-many mapping in NHibernate

    - by Chris Stewart
    I'm looking to create a many to many relationship using NHibernate. I'm not sure how to map these in the XML files. I have not created the classes yet, but they will just be basic POCOs. Tables Person personId name Competency competencyId title Person_x_Competency personId competencyId Would I essentially create a List in each POCO for the other class? Then map those somehow using the NHibernate configuration files?

    Read the article

  • Informix, NHibernate, TransactionScope interaction difficulties

    - by John Prideaux
    I have a small program that is trying to wrap an NHibernate insert into an Informix database in a TransactionScope object using the Informix .NET Provider. I am getting the error specified below. The code without the TransactionScope object works -- including when the insert is wrapped in an NHibernate session transaction. Any ideas on what the problem is? BTW, without the EnterpriseServicesInterop, the Informix .NET Provider will not participate in a TransactionScope transaction (verified without NHibernate involved). Code Snippet: public static void TestTScope() { Employee johnp = new Employee { name = "John Prideaux" }; using (TransactionScope tscope = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions() { Timeout = new TimeSpan(0, 1, 0), IsolationLevel = IsolationLevel.ReadCommitted }, EnterpriseServicesInteropOption.Full)) { using (ISession session = OpenSession()) { session.Save(johnp); Console.WriteLine("Saved John to the database"); } } Console.WriteLine("Transaction should be rolled back"); } static ISession OpenSession() { if (factory == null) { Configuration c = new Configuration(); c.AddAssembly(Assembly.GetCallingAssembly()); factory = c.BuildSessionFactory(); } return factory.OpenSession(); } static ISessionFactory factory; Stack Trace: NHibernate.ADOException was unhandled Message="Could not close IBM.Data.Informix.IfxConnection connection" Source="NHibernate" StackTrace: at NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn) at NHibernate.Connection.DriverConnectionProvider.CloseConnection(IDbConnection conn) at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Release() at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) at NHibernate.Cfg.Configuration.BuildSessionFactory() at HelloNHibernate.Employee.OpenSession() in D:\Development\ScratchProject\HelloNHibernate\Employee.cs:line 73 at HelloNHibernate.Employee.TestTScope() in D:\Development\ScratchProject\HelloNHibernate\Employee.cs:line 53 at HelloNHibernate.Program.Main(String[] args) in D:\Development\ScratchProject\HelloNHibernate\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: IBM.Data.Informix.IfxException Message="ERROR - no error information available" Source="IBM.Data.Informix" ErrorCode=-2147467259 StackTrace: at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) at IBM.Data.Informix.IfxConnection.DisposeClose() at IBM.Data.Informix.IfxConnection.Close() at NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn) InnerException:

    Read the article

  • Manipulate score/rank on query results from NHibernate.Search

    - by Fernando Figueiredo
    I've been working with NHibernate, NHibernate.Search and Lucene.Net to improve the search engine used on the website I develop. Basically, I use it to search contents of corporations specification documents. This is not to be confused with Lucene's notion of documents: in my case, a specification document (which I'll hereafter call a "specdoc") can contain many pages, and the content of these pages are the ones that are actually indexed (thus, the pages themselves are the ones that fall into Lucene's concept of documents). So, the pages belong to a specdoc, that in turn belong to a corporation (so, a corporation can have many specdocs). I'm using NHibernate.Search "IndexEmbedded" and "ContainedIn" attributes to associate the pages with their specdoc and the specdocs to their corporations, so I can query for terms in specdoc pages and have Lucene/NH.Search return either the pages themselves, the specdocs, or the corporations that match the query on the pages. I can query this way and get ranked results, thus presenting results (that is, corporations, specdocs or pages) by relevance, which is great. But now I need something more. Specifically in the case where I query terms and have NH.Search return the corporations that match, I need to manually/artificially tune the score of some of the results, because there are corporations that I want to show up on the top of the result set - think of "sponsored results". I'm thinking of doing it on my application, maybe creating an entity/database table that contain an association to the corporation entity, and a score boost value. But I don't know how to feed this to Lucene and have it boost the results accordingly at search time. Initially I thought about deriving a Similarity class to do this, but it doesn't look like Similarity can be used to modify result sets at search time. As per this page, it looks like what I need is to mess around with weight or scoring. But the docs are a little superficial in that there are no examples on how to implement a custom scoring, let alone integrate it with NH.Search. So, does anyone know how to do this, or point me to some documentation or working example on how to do something similar? Thanks!

    Read the article

  • SqlLite/Fluent NHibernate integration test harness initialization not repeatable after large data se

    - by Mark Rogers
    In one of my main data integration test harnesses I create and use Fluent NHibernate's SingleConnectionSessionSourceForSQLiteInMemoryTesting, to get a fresh session for each test. After each test, I close the connection, session, and session factory, and throw out the nested StructureMap container they came from. This works for almost any simple data integration test I can think, including ones that utilize Fluent NHib's PersistenceSpecification object. When I test the application's lengthy database bootstrapping process, which creates and saves thousands of domain objects, I start seeing issues. It's not that the setup and tear down fails, in fact, the test successfully bootstraps the in-memory database as the application would bootstrap the real database in the production environment. The problem occurs when the database bootstrapping occurs a second time on a new in-memory database, with a new session and session factory. The error is: NHibernate.StaleStateException : Unexpected row count: 0; expected: 1 The row count is indeed Unexpected, the row that the application under test is looking for should be in the session. You see, it's not that any data from the last integration test is sticking around, it's that for some reason the session just stops working mid-database-boostrap. And I've looked everywhere for a place I might be holding on to an old session and I can't find one. I've searched through the code for static singleton objects, but there are none anywhere near the code in question. I have a couple StructureMap InstanceScope singleton's but they are getting thrown out with each nested container that is lost after every test teardown. I've tried every possible variation on disposing and closing every object involved with each test teardown and it still fails on this lengthy database bootstrap. But non-bootstrap related database tests appear to work fine. I'm starting to run out of options and may have to surrender lengthy database integration tests in favor of WatiN-based acceptance tests. Can anyone give me any clue about how I can figure out why some of my SingleConnectionSessionSourceForSQLiteInMemoryTesting aren't repeatable? Any advice at all, about how to make an NHibernate SqlLite database integration test harness repeatable?

    Read the article

  • NHibernate Child items query using Parent Id

    - by thorkia
    So I have a set up similar to this questions: Parent Child Setup Everything works great when saving the parent and the children. However, I seem to have a problem when selecting the children. I can't seem to get all the children with a specific parent. This fails with: NHibernate.QueryException: could not resolve property: ParentEntity_id of: Test.Data.ChildEntity Here is my code: public IEnumerable<ChildEntity> GetByParent(ParentEntity parent) { using (ISession session = OrmHelper.OpenSession()) { return session.CreateCriteria<ChildEntity>().Add(Restrictions.Eq("ParentEntity_id ", parent.Id)).List<ChildEntity>(); } } Any help in building a proper function to get all the items would be appreciated. Oh, I am using Fluent NHibernate to construct the mappings - version 1 RTM and NHibernate 2.1.2 GA If you need more information, let me know. As per you request, my fluent mappings: public ParentEntityMap() { Id(x => x.Id); Map(x => x.Name); Map(x => x.Code).UniqueKey("ukCode"); HasMany(x => x.ChildEntity).LazyLoad() .Inverse().Cascade.SaveUpdate(); } public ChildEntityMap() { Id(x => x.Id); Map(x => x.Amount); Map(x => x.LogTime); References(x => x.ParentEntity); } That maps to the following 2 tables: CREATE TABLE "ParentEntity" ( Id integer, Name TEXT, Code TEXT, primary key (Id), unique (Code) ) CREATE TABLE "ChildEntity" ( Id integer, Amount NUMERIC, LogTime DATETIME, ParentEntity_id INTEGER, primary key (Id) ) The data store in SQLite.

    Read the article

  • NHibernate2 query is wired when fetch the collection from the proxy. Is this correct behavior?

    - by ensecoz
    This is my class: public class User { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<UserFriend> Friends { get; protected set; } } public class UserFriend { public virtual int Id { get; set; } public virtual User User { get; set; } public virtual User Friend { get; set; } } This is my mapping (Fluent NHibernate): public class UserMap : ClassMap<User> { public UserMap() { Id(x => x.Id, "UserId").GeneratedBy.Identity(); HasMany<UserFriend>(x => x.Friends); } } public class UserFriendMap : ClassMap<UserFriend> { public UserFriendMap() { Id(x => x.Id, "UserFriendId").GeneratedBy.Identity(); References<User>(x => x.User).TheColumnNameIs("UserId").CanNotBeNull(); References<User>(x => x.Friend).TheColumnNameIs("FriendId").CanNotBeNull(); } } The problem is when I execute this code: User user = repository.Load(1); User friend = repository.Load(2); UserFriend userFriend = new UserFriend(); userFriend.User = user; userFriend.Friend = friend; friendRepository.Save(userFriend); var friends = user.Friends; At the last line, NHibernate generate this query for me: SELECT friends0_.UserId as UserId1_, friends0_.UserFriendId as UserFrie1_1_, friends0_.UserFriendId as UserFrie1_6_0_, friends0_.FriendId as FriendId6_0_, friends0_.UserId as UserId6_0_ FROM "UserFriend" friends0_ WHERE friends0_.UserId=@p0; @p0 = '1' QUESTION: Why the query look very wired? It should select only 3 fields (which are UserFriendId, UserId, FriendId) Am I right? or there is something going on inside NHibernate?

    Read the article

  • Strategies for Mapping Views in NHibernate

    - by Nathan Fisher
    It seems that NHibernate needs to have an id tag specified as part of the mapping. This presents a problem for views as most of the time (in my experience) a view will not have an Id. I have mapped views before in nhibernate, but they way I did it seemed to be be messy to me. Here is a contrived example of how I am doing it currently. Mapping <class name="ProductView" table="viewProduct" mutable="false" > <id name="Id" type="Guid"> <generator class="guid.comb" /> </id> <property name="Name" /> <!-- more properties --> </class> View SQL Select NewID() as Id, ProductName as Name, --More columns From Product Class public class ProductView { public virtual Id {get; set;} public virtual Name {get; set;} } I don't need an Id for the product or in the case of some views I may not have an id for the view, depending on if I have control over the View Is there a better way of mapping views to objects in nhibernate?

    Read the article

  • NHibernate + Fluent long startup time

    - by PaRa
    Hi all, am new to NHibernate. When performing below test took 11.2 seconds (debug mode) i am seeing this large startup time in all my tests (basically creating the first session takes a tone of time) setup = Windows 2003 SP2 / Oracle10gR2 latest CPU / ODP.net 2.111.7.20 / FNH 1.0.0.636 / NHibernate 2.1.2.4000 / NUnit 2.5.2.9222 / VS2008 SP1 using System; using System.Collections; using System.Data; using System.Globalization; using System.IO; using System.Text; using System.Data; using NUnit.Framework; using System.Collections.Generic; using System.Data.Common; using NHibernate; using log4net.Config; using System.Configuration; using FluentNHibernate; [Test()] public void GetEmailById() { Email result; using (EmailRepository repository = new EmailRepository()) { results = repository.GetById(1111); } Assert.IsTrue(results != null); } public class EmailRepository : RepositoryBase { public EmailRepository():base() { } } In my RepositoryBase public T GetById(object id) { using (var session = sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { try { T returnVal = session.Get(id); transaction.Commit(); return returnVal; } catch (HibernateException ex) { // Logging here transaction.Rollback(); return null; } } } The query time is very small. The resulting entity is really small. Subsequent queries are fine. Its seems to be getting the first session started. Has anyone else seen something similar?

    Read the article

  • Fluent NHibernate - Set reference key columns to null

    - by Matt
    Hi, I have a table of Appointments and a table of AppointmentOutcomes. On my Appointments table I have an OutcomeID field which has a foreign key to AppointmentOutcomes. My Fluent NHibernate mappings look as follows; Table("Appointments"); Not.LazyLoad(); Id(c => c.ID).GeneratedBy.Assigned(); Map(c => c.Subject); Map(c => c.StartTime); References(c => c.Outcome, "OutcomeID"); Table("AppointmentOutcomes"); Not.LazyLoad(); Id(c => c.ID).GeneratedBy.Assigned(); Map(c => c.Description); Using NHibernate, if I delete an AppointmentOutcome an exception is thrown because the foreign key is invalid. What I would like to happen is that deleting an AppointmentOutcome would automatically set the OutcomeID of any Appointments that reference the AppointmentOutcome to NULL. Is this possible using Fluent NHibernate?

    Read the article

  • Fluent NHibernate no data being returned

    - by czuroski
    Hello, I have been successfully using NHibernate, but now I am trying to move to Fluent NHibernate. I have created all of my mapping files and set up my session manager to use a Fluent Configuration. I then run my application and it runs successfully, but no data is returned. There are no errors or any indication that there is a problem, but nothing runs. when using NHibernate, if I don't set my hbm xml files as an embedded resource, this same thing happens. This makes me wonder what I have to set my Map classes to. Right now, they are just set to Compile, and they are compiled into the dll, which I can see by disassembling it. Does anyone have any thoughts as to what may be happening here? Thanks private ISessionFactory GetSessionFactory() { return Fluently.Configure() .Database( IfxOdbcConfiguration .Informix1000 .ConnectionString("Provider=Ifxoledbc.2;Password=mypass;Persist Security Info=True;User ID=myuser;Data Source=mysource") .Dialect<InformixDialect1000>() .ProxyFactoryFactory<ProxyFactoryFactory>() .Driver<OleDbDriver>() .ShowSql() ) .Mappings( m => m.FluentMappings .AddFromAssemblyOf<cmCase>() .AddFromAssemblyOf<attorney>() .AddFromAssemblyOf<creditor>() .AddFromAssemblyOf<party>() .AddFromAssemblyOf<person>() .AddFromAssemblyOf<sardbk>() .AddFromAssemblyOf<schedule>() //x => x.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()) //.ExportTo("C:\\mappings") ) .BuildSessionFactory(); }

    Read the article

  • NHibernate LINQ query throws error "Could not resolve property"

    - by Xorandor
    I'm testing out using LINQ with NHibernate but have run into some problems with resolving string.length. I have the following public class DC_Control { public virtual int ID { get; private set; } public virtual string Name { get; set; } public virtual bool IsEnabled { get; set; } public virtual string Url { get; set; } public virtual string Category { get; set; } public virtual string Description { get; set; } public virtual bool RequireScriptManager { get; set; } public virtual string TriggerQueryString { get; set; } public virtual DateTime? DateAdded { get; set; } public virtual DateTime? DateUpdated { get; set; } } public class DC_ControlMap : ClassMap<DC_Control> { public DC_ControlMap() { Id(x => x.ID); Map(x => x.Name).Length(128); Map(x => x.IsEnabled); Map(x => x.Url); Map(x => x.Category); Map(x => x.Description); Map(x => x.RequireScriptManager); Map(x => x.TriggerQueryString); Map(x => x.DateAdded); Map(x => x.DateUpdated); } } private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) .ExposeConfiguration(c => c.SetProperty("connection.connection_string", "CONNSTRING")) .ExposeConfiguration(c => c.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle")) .BuildSessionFactory(); } public static void test() { using (ISession session = sessionFactory.OpenSession()) { var sqlQuery = session.CreateSQLQuery("select * from DC_Control where LEN(url) > 80").AddEntity(typeof(DC_Control)).List<DC_Control>(); var linqQuery= session.Linq<DC_Control>().Where(c => c.Url.Length > 80).ToList(); } } In my test method I first try and perform the query using SQL, this works just fine. Then I want to do the same thing in LINQ, and it throws the following error: NHibernate.QueryException: could not resolve property: Url.Length of: DC_Control I've searched alot for this "could not resolve property" error, but I can't quite figure out, what this means. Is this because the LINQ implementation is not complete? If so it's a bit disappointing coming from Linq2Sql where this would just work. I also tried it setting up the mapping with a hbm.xml instead of using FluentNHibernate but it produced teh same error.

    Read the article

  • NHibernate Pitfalls: Cascades

    - by Ricardo Peres
    This is part of a series of posts about NHibernate Pitfalls. See the entire collection here. For entities that have associations – one-to-one, one-to-many, many-to-one or many-to-many –, NHibernate needs to know what to do with their related entities, in three particular moments: when saving, updating or deleting. In particular, there are two possible behaviors: either ignore these related entities or cascade changes to them. NHibernate allows setting the cascade behavior for each association, and the default behavior is not to cascade (ignore). The possible cascade options are: None Ignore, this is the default Save-Update If the entity is being saved or updated, also save any related entities that are either not saved or have been modified and associate these related entities to the root entity. Generally safe Delete If the entity is being deleted, also delete the related entities. This is only useful for parent-child relations Delete-Orphan Identical to Delete, with the addition that if once related entity is removed from the association – orphaned –, also delete it. Also only for parent-child All Combination of Save-Update and Delete, usually that’s what we want (for parent-child relations, of course) All-Delete-Orphan Same as All plus delete any related entities who lose their relationship In summary, Save-Update is generally what you want in most cases. As for the Delete variations, they should only be used if the related entities depend on the root entity (parent-child), so that deleting the root entity and not their related entities would result in a constraint violation on the database.

    Read the article

  • How to change Fluent NHibernate reference column name on a HasMany relationship using IHasManyConven

    - by snicker
    Currently I'm using Fluent NHibernate to generate my database schema, but I want the entities in a HasMany relationship to point to a different column for the reference. IE, this is what NHibernate will generate in the creation DDL: alter table `Pony` add index (Stable_ID), add constraint Ponies_Stable foreign key (Stable_Id) references `Stable` (Id); This is what I want to have: alter table `Pony` add index (Stable_ID), add constraint Ponies_Stable foreign key (Stable_Id) references `Stable` (EntityId); Where Stable.ID would be the primary key and Stable.EntityId is just another column that I set. I have a class already that looks like this: public class ForeignKeyReferenceConvention : IHasManyConvention { public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.All(); //What goes here so that I can change the reference column? } } What do I have to do to get the reference column to change?

    Read the article

  • Nhibernate upgraded getting 'Antlr.Runtime.NoViableAltException' on outer join using *=

    - by user86431
    so we upgraded to newer Nhibernate and Fluent Nhibernate. now I' getting this exception: FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 459 On this hql, which worked fine before the upgrade. SELECT s.StudId, s.StudLname, s.StudFname, s.StudMi, s.Ssn, s.Sex, s.Dob, et.EnrtypeId, et.Active, et.EnrId, sss.StaffLname, sss.StaffFname, sss.StaffMi,vas.CurrentAge FROM CIS3G.Jcdc.EO.StudentEO s , CIS3G.Jcdc.EO.EnrollmentEO e , CIS3G.Jcdc.EO.EnrollmentTypeEO et , CIS3G.Jcdc.EO.VwStaffStudentStaffEO sss, CIS3G.Jcdc.EO.VwAgeStudentEO vas WHERE ( e.EnrId = et.EnrId ) AND ( s.StudId = vas.StudId ) AND ( s.StudId = e.StudId ) AND ( et.EnrtypeId *= sss.EnrtypeId ) AND ( Isnull ( sss.StudStaffRoleCd , 1044 ) = 1044 ) AND ( s.StudId = 4000 ) Clearly it does nto like the *= syntax, I tried rewritign is as ansi sql outer join and no joy. Can anyone tell me what ineed to change the sql to so I can get the outer join to work correctly? Thanks, Eric-

    Read the article

  • Fluent NHibernate - exception occurred during configuration of persistence layer

    - by inutan
    Hello there, I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file. Following is the configuration code where I am getting error: var configuration = new Configuration(); configuration.Configure(); _sessionFactory = Fluently.Configure(configuration) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Template>()) .BuildSessionFactory(); return _sessionFactory; But When NHibernate is trying to configure, I am getting floowing error: An exception occurred during configuration of persistence layer. Please help.

    Read the article

  • using (Fluent) NHibernate with StructureMap (or any IoCC)

    - by Andrew Bullock
    Hi, On my quest to learn NHibernate I have reached the next hurdle; how should I go about integrating it with StructureMap? Although code examples are very welcome, I'm more interested in the general procedure. What I was planning on doing was... Use Fluent NHibernate to create my class mappings for use in NHibs Configuration Implement ISession and ISessionFactory Bootstrap an instance of my ISessionFactory into StructureMap as a singleton Register ISession with StructureMap, with per-HttpRequest caching However, don't I need to call various tidy-up methods on my session instance at the end of the HttpRequest (because thats the end of its life)? If i do the tidy-up in Dispose(), will structuremap take care of this for me? If not, what am I supposed to do? Thanks Andrew

    Read the article

  • Using a Generic Repository pattern with fluent nHibernate

    - by alex
    I'm currently developing a medium sized application, which will access 2 or more SQL databases, on different sites etc... I am considering using something similar to this: http://mikehadlow.blogspot.com/2008/03/using-irepository-pattern-with-linq-to.html However, I want to use fluent nHibernate, in place of Linq-to-SQL (and of course nHibernate.Linq) Is this viable? How would I go about configuring this? Where would my mapping definitions go etc...? This application will eventually have many facets - from a WebUI, WCF Library and Windows applications / services. Also, for example on a "product" table, would I create a "ProductManager" class, that has methods like: GetProduct, GetAllProducts etc... Any pointers are greatly received.

    Read the article

  • How does Fluent NHibernate support the Import Entity

    - by Bender
    I want to create a strongly type object from a fluent NHibernate query. If I were using HQL and NHibernate I belive I would need: the class for the output Namespace Model Public Class namecount Public Overridable Property lastname() as string ... Public Overridable Property lastnamecount() as integer ... Public Sub New(lastname as string, count as integer) ... End Class End Namespace an .hbm.xml file <?xml ...> <hibernate-mapping ...> <import class="model.namecount,model"> </hibernate-mapping> and of course the query _session.createquery("select new namecount(lastname, count(lastname)) ...") (The above is a paraphrased example taken from one of the 2008 SummerofNHibernate videos) I cannot find any examples of how to do this with fluent (even in C#), is it possible? If it isn't is there a VB example of how to mix Fluent and .hbm.xml

    Read the article

  • Many-To-Many Query with Linq-To-NHibernate

    - by rjygraham
    Ok guys (and gals), this one has been driving me nuts all night and I'm turning to your collective wisdom for help. I'm using Fluent Nhibernate and Linq-To-NHibernate as my data access story and I have the following simplified DB structure: CREATE TABLE [dbo].[Classes]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](100) NOT NULL, [StartDate] [datetime2](7) NOT NULL, [EndDate] [datetime2](7) NOT NULL, CONSTRAINT [PK_Classes] PRIMARY KEY CLUSTERED ( [Id] ASC ) CREATE TABLE [dbo].[Sections]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [ClassId] [bigint] NOT NULL, [InternalCode] [varchar](10) NOT NULL, CONSTRAINT [PK_Sections] PRIMARY KEY CLUSTERED ( [Id] ASC ) CREATE TABLE [dbo].[SectionStudents]( [SectionId] [bigint] NOT NULL, [UserId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_SectionStudents] PRIMARY KEY CLUSTERED ( [SectionId] ASC, [UserId] ASC ) CREATE TABLE [dbo].[aspnet_Users]( [ApplicationId] [uniqueidentifier] NOT NULL, [UserId] [uniqueidentifier] NOT NULL, [UserName] [nvarchar](256) NOT NULL, [LoweredUserName] [nvarchar](256) NOT NULL, [MobileAlias] [nvarchar](16) NULL, [IsAnonymous] [bit] NOT NULL, [LastActivityDate] [datetime] NOT NULL, PRIMARY KEY NONCLUSTERED ( [UserId] ASC ) I omitted the foreign keys for brevity, but essentially this boils down to: A Class can have many Sections. A Section can belong to only 1 Class but can have many Students. A Student (aspnet_Users) can belong to many Sections. I've setup the corresponding Model classes and Fluent NHibernate Mapping classes, all that is working fine. Here's where I'm getting stuck. I need to write a query which will return the sections a student is enrolled in based on the student's UserId and the dates of the class. Here's what I've tried so far: 1. var sections = (from s in this.Session.Linq<Sections>() where s.Class.StartDate <= DateTime.UtcNow && s.Class.EndDate > DateTime.UtcNow && s.Students.First(f => f.UserId == userId) != null select s); 2. var sections = (from s in this.Session.Linq<Sections>() where s.Class.StartDate <= DateTime.UtcNow && s.Class.EndDate > DateTime.UtcNow && s.Students.Where(w => w.UserId == userId).FirstOrDefault().Id == userId select s); Obviously, 2 above will fail miserably if there are no students matching userId for classes the current date between it's start and end dates...but I just wanted to try. The filters for the Class StartDate and EndDate work fine, but the many-to-many relation with Students is proving to be difficult. Everytime I try running the query I get an ArgumentNullException with the message: Value cannot be null. Parameter name: session I've considered going down the path of making the SectionStudents relation a Model class with a reference to Section and a reference to Student instead of a many-to-many. I'd like to avoid that if I can, and I'm not even sure it would work that way. Thanks in advance to anyone who can help. Ryan

    Read the article

  • nhibernate webforms with class library

    - by frosty
    very new to nhibernate. I'm a little confused on where features should live. I have the following solution 1) MyProject.Web ( web forms application) 2) MyProject.Domain( class lib) - nhibernate.config - product.hbm.xml So is it correct I should put the following method in a IHttpModule? ( i can't use a global asax as it's use by the CMS i'm running ) Where should the connectionString live? HTTPModule in web forms application private static ISessionFactory CreateSessionFactory() { var cfg = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nhibernate.config")); cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionStringName, System.Environment.MachineName); NHibernateProfiler.Initialize(); return cfg.BuildSessionFactory(); } nhibernate.config <?xml version="1.0" encoding="utf-8" ?> NHibernate.Dialect.MsSql2005Dialect NHibernate.Connection.DriverConnectionProvider NHibernate.Driver.SqlClientDriver 16 web NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle enter code here

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >