Search Results

Search found 4565 results on 183 pages for 'nhibernate mapping'.

Page 31/183 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • NHibernate + Sql Compact + IoC - Connection Managment

    - by Michael
    When working with NHibernate and Sql Compact in a Windows Form application I am wondering what is the best practice for managing connections. With SQL CE I have read that you should keep your connection open vs closing it as one would typically do with standard SQL. If that is the case and your using a IoC, would you make your repositories lifetime be singletons so they exist forever or dispose of them after you perform a "Unit of Work". Also is there a way to determine the number of connections open to Sql CE?

    Read the article

  • nhibernate intercept select query

    - by mjmcloug
    Hey, I'm looking at the nhibernate interceptor. It seems to be able to intercept save, update and delete queries but is there anyway I can intercept a select query. The problem I have is that I automatically want to append some additional sql filters to the executing sql statement in certain cases. Any thoughts Thanks Mat

    Read the article

  • How to do a proper search with nhibernate

    - by Denis Rosca
    Hello everyone, i'm working on a small project that is supposed to allow basic searches of the database. Currently i'm using nhibernate for the database interaction. In the database i have 2 tables: Person and Address. The Person table has a many-to-one relationship with Address. The code i've come up with for doing searches is: public IList<T> GetByParameterList(List<QueryParameter> parameterList) { if (parameterList == null) { return GetAll(); } using (ISession session = NHibernateHelper.OpenSession()) { ICriteria criteria = session.CreateCriteria<T>(); foreach (QueryParameter param in parameterList) { switch (param.Constraint) { case ConstraintType.Less: criteria.Add(Expression.Lt(param.ParameterName, param.ParameterValue)); break; case ConstraintType.More: criteria.Add(Expression.Gt(param.ParameterName, param.ParameterValue)); break; case ConstraintType.LessOrEqual: criteria.Add(Expression.Le(param.ParameterName, param.ParameterValue)); break; case ConstraintType.EqualOrMore: criteria.Add(Expression.Ge(param.ParameterName, param.ParameterValue)); break; case ConstraintType.Equals: criteria.Add(Expression.Eq(param.ParameterName, param.ParameterValue)); break; case ConstraintType.Like: criteria.Add(Expression.Like(param.ParameterName, param.ParameterValue)); break; } } try { IList<T> result = criteria.List<T>(); return result; } catch { //TODO: Implement some exception handling throw; } } } The query parameter is a helper object that i use to create criterias and send it to the dal, it looks like this: public class QueryParameter { public QueryParameter(string ParameterName, Object ParameterValue, ConstraintType constraintType) { this.ParameterName = ParameterName; this.ParameterValue = ParameterValue; this.Constraint = constraintType; } public string ParameterName { get; set; } public Object ParameterValue { get; set; } public ConstraintType Constraint { get; set; } } Now this works well if i'm doing a search like FirstName = "John" , but not when i try to give a parameter like Street = "Some Street". It seems that nhibernate is looking for a street column in the Person table but not in the Address table. Any idea on how should i change my code for so i could do a proper search? Tips? Maybe some alternatives? Disclaimer: i'm kind of a noob so please be gentle ;) Thanks, Denis.

    Read the article

  • Where clause in nhibernate map

    - by Phil Whittaker
    I have an Nhibernate hbm that maps a many to many relationship. For database simplicity it uses a where clause on the bag to filter the joining table. this works well until I start to test and I use the hbm file to create a database from the generated schema. The root and user tags columns aren't created. In the hbm file how do I define these two columns so they are generated in the schema?

    Read the article

  • EF query to fluent nhibernate query

    - by Shlomi Levi
    I have EF Query: IEnumerable<Account> accounts = (from a in dc.Accounts join m in dc.GroupMembers on a.AccountID equals m.AccountID where m.GroupID == GroupID && m.IsApproved select a).Skip((_configuration.NumberOfRecordsInPage * (PageNumber - 1))) .Take(_configuration.NumberOfRecordsInPage); How to write it in fluent nhibernate query with Session.CreateCriteria<? (My problem is with Join) Regards,

    Read the article

  • NHibernate - ISession

    - by Guilherme Cardoso
    Hi About the declaration of ISession. Should we close the Session everytime we use it, or should we keep it open? I'm asking this because in manual of NHibernate (nhforge.org) they recommend us to declare it once in Application_Start for example, but i don't know if we should close it everytime we use. Thanks

    Read the article

  • NHibernate - using custom sql query for a column

    - by stacker
    Is there anyway to use custom sql with NHibernate? I want to use custom sql for a specific column. select id, viewsCount, commentsCount, 0.2 * viewsCount / (select top 1 viewsCount from articles where isActive = 1 order by viewsCount DESC) as priorityViews, 0.8 * commentsCount / (select top 1 commentsCount from articles where isActive = 1 order by commentsCount DESC) as priorityComments, round(0.2 * viewsCount / (select top 1 viewsCount from articles where isActive = 1 order by viewsCount DESC) + 0.8 * commentsCount / (select top 1 commentsCount from articles where isActive = 1 order by commentsCount DESC), 1) as priority from articles

    Read the article

  • Select latest group by in nhibernate

    - by Kendrick
    I have Canine and CanineHandler objects in my application. The CanineHandler object has a PersonID (which references a completely different database), an EffectiveDate (which specifies when a handler started with the canine), and a FK reference to the Canine (CanineID). Given a specific PersonID, I want to find all canines they're currently responsible for. The (simplified) query I'd use in SQL would be: Select Canine.* from Canine inner join CanineHandler on(CanineHandler.CanineID=Canine.CanineID) inner join (select CanineID,Max(EffectiveDate) MaxEffectiveDate from caninehandler group by CanineID) as CurrentHandler on(CurrentHandler.CanineID=CanineHandler.CanineID and CurrentHandler.MaxEffectiveDate=CanineHandler.EffectiveDate) where CanineHandler.HandlerPersonID=@PersonID Edit: Added mapping files below: <class name="CanineHandler" table="CanineHandler" schema="dbo"> <id name="CanineHandlerID" type="Int32"> <generator class="identity" /> </id> <property name="EffectiveDate" type="DateTime" precision="16" not-null="true" /> <property name="HandlerPersonID" type="Int64" precision="19" not-null="true" /> <many-to-one name="Canine" class="Canine" column="CanineID" not-null="true" access="field.camelcase-underscore" /> </class> <class name="Canine" table="Canine"> <id name="CanineID" type="Int32"> <generator class="identity" /> </id> <property name="Name" type="String" length="64" not-null="true" /> ... <set name="CanineHandlers" table="CanineHandler" inverse="true" order-by="EffectiveDate desc" cascade="save-update" access="field.camelcase-underscore"> <key column="CanineID" /> <one-to-many class="CanineHandler" /> </set> <property name="IsDeleted" type="Boolean" not-null="true" /> </class> I haven't tried yet, but I'm guessing I could do this in HQL. I haven't had to write anything in HQL yet, so I'll have to tackle that eventually anyway, but my question is whether/how I can do this sub-query with the criterion/subqueries objects. I got as far as creating the following detached criteria: DetachedCriteria effectiveHandlers = DetachedCriteria.For<Canine>() .SetProjection(Projections.ProjectionList() .Add(Projections.Max("EffectiveDate"),"MaxEffectiveDate") .Add(Projections.GroupProperty("CanineID"),"handledCanineID") ); but I can't figure out how to do the inner join. If I do this: Session.CreateCriteria<Canine>() .CreateCriteria("CanineHandler", "handler", NHibernate.SqlCommand.JoinType.InnerJoin) .List<Canine>(); I get an error "could not resolve property: CanineHandler of: OPS.CanineApp.Model.Canine". Obviously I'm missing something(s) but from the documentation I got the impression that should return a list of Canines that have handlers (possibly with duplicates). Until I can make this work, adding the subquery isn't going to work... I've found similar questions, such as http://stackoverflow.com/questions/747382/only-get-latest-results-using-nhibernate but none of the answers really seem to apply with the kind of direct result I'm looking for. Any help or suggestion is greatly appreciated.

    Read the article

  • Check for active connection in NHibernate

    - by Dofs
    I have a system with a few different databases, and I would like to check if a certain database is down, and if so display a message to the user. Is it possible in NHibernate to check if there is an active connection to the database, without having to request data and then catch the exception?

    Read the article

  • Stateless NHibernate for querying

    - by JontyMC
    We have a database that is updated via a background process. We are using NHibernate to query the data for display on the web UI, so we don't need change tracking or lazy-loading. If we mark all the mappings as mutable="false", is this the same as using a stateless session?

    Read the article

  • NHibernate does not update entity when repository is passed by constructor

    - by Alex
    Hi everybody, I am developing with NHibernate for the first time in conjunction with ASP.NET MVC and StructureMap. The CodeCampServer serves as a great example for me. I really like the different concepts which were implemented there and I can learn a lot from it. In my controllers I use Constructur Dependency Injection to get an instance of the specific repository needed. My problem is: If I change an attribute of the customer the customer's data is not updated in the database, although Commit() is called on the transaction object (by a HttpModule). public class AccountsController : Controller { private readonly ICustomerRepository repository; public AccountsController(ICustomerRepository repository) { this.repository = repository; } public ActionResult Save(Customer customer) { Customer customerToUpdate = repository .GetById(customer.Id); customerToUpdate.GivenName = "test"; //<-- customer does not get updated in database return View(); } } On the other hand this is working: public class AccountsController : Controller { [LoadCurrentCustomer] public ActionResult Save(Customer customer) { customer.GivenName = "test"; //<-- Customer gets updated return View(); } } public class LoadCurrentCustomer : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { const string parameterName = "Customer"; if (filterContext.ActionParameters.ContainsKey(parameterName)) { if (filterContext.HttpContext.User.Identity.IsAuthenticated) { Customer CurrentCustomer = DependencyResolverFactory .GetDefault() .Resolve<IUserSession>() .GetCurrentUser(); filterContext.ActionParameters[parameterName] = CurrentCustomer; } } base.OnActionExecuting(filterContext); } } public class UserSession : IUserSession { private readonly ICustomerRepository repository; public UserSession(ICustomerRepository customerRepository) { repository = customerRepository; } public Customer GetCurrentUser() { var identity = HttpContext.Current.User.Identity; if (!identity.IsAuthenticated) { return null; } Customer customer = repository.GetByEmailAddress(identity.Name); return customer; } } I also tried to call update on the repository like the following code shows. But this leads to an NHibernateException which says "Illegal attempt to associate a collection with two open sessions". Actually there is only one. public ActionResult Save(Customer customer) { Customer customerToUpdate = repository .GetById(customer.Id); customer.GivenName = "test"; repository.Update(customerToUpdate); return View(); } Does somebody have an idea why the customer is not updated in the first example but is updated in the second example? Why does NHibernate say that there are two open sessions?

    Read the article

  • Is there any NHibernate book?

    - by Przemek
    Taking into consideration that NHibernate has been available for some time I thought that there would be a book available already. A search on amazon turned out just one that apparently has been delayed (Manning). Meanwhile, it looks that there seems to be coming many books on Microsoft Entity Framework. Is there any significance in that?

    Read the article

  • NHibernate Empty Set Clauses in SQL Update Statements

    - by Brian Wilkinson
    I'm getting SQL update statements from NHibernate having a empty set clause ie UPDATE SET WHERE x == ? This propblem is occuring when a child entity is being updated for some reason the sql statement is being run against the Parent Entity, for some reason NHibenate is saying the parent has changed but when the set clause is being built no changes are found, can anyone help. The application I am constructing isn 3 tier. The domain entities are light weight data contract only entities.

    Read the article

  • How to achieve an eagerly loaded, filtered child collection with the NHibernate criteria API

    - by vakman
    Is it possible to use the criteria api to load a set of parent objects along with a filtered, eagerly loaded set of child objects? I'm trying to query a list of categories and at the same time load the categories products that start with the letter M. The query below gives me the results I want but the Products are not eagerly loaded, that is NHibernate performs additional queries when I enumerate the Product collection: var categoriesWithProducts = session.CreateCriteria<Category>() .SetFetchMode("Products", FetchMode.Eager) .CreateCriteria("Products") .Add(Expression.Like("Name", "M%")) .List<Category>(); What am I missing here?

    Read the article

  • Fluent NHibernate - Map 2 tables to one class

    - by Morten Schmidt
    Hi I have a table structure something like this table Employees EmployeeID EmployeeLogin EmployeeCustID table Customers CustomerID CustomerName What i would like is to map the structure above to one single class named: Class Employee EmployeeID EmployeeLogin EmployeeName How do i do that with fluent nhibernate ?

    Read the article

  • Loading a entity IDs CSV column as hydrated entities in NHibernate

    - by James L
    I have a number of database table that looks like this: EntityId int : 1 Countries1: "1,2,3,4,5" Countries2: "7,9,10,22" I would like to have NHibernate load the Country entities identifed as 1,2,3,4,5,7,9 etc. whenever my EntityId is loaded. The reason for this is that we want to avoid a proliferation of joins, as there are scores of these collections.

    Read the article

  • NHibernate and reporting

    - by Paul Knopf
    I am building a website on top of nhibernate. Is there any efficient way to build reports? BY reports, I mean is there anyway to execute a complicated query that grabs random pieces of data? StoreProcedures? Hql? Can I get single, non mapped values from hql?

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >