Search Results

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

Page 40/183 | < Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >

  • Using Lite Version of Entity in nHibernate Relations?

    - by Amitabh
    Is it a good idea to create a lighter version of an Entity in some cases just for performance reason pointing to same table but with fewer columns mapped. E.g If I have a Contact Table which has 50 Columns and in few of the related entities I might be interested in FirstName and LastName property is it a good idea to create a lightweight version of Contact table. E.g. public class ContactLite { public int Id {get; set;} public string FirstName {get; set;} public string LastName {get; set;} } Also is it possible to map multiple classes to same table?

    Read the article

  • How to query flags stored as enum in NHibernate

    - by SztupY
    How to do either a HQL or a Criteria search (the latter is preferred) involving an enum that is used as flags. In other words, I have a persisted enum property that stores some kind of flags. I want to query all the records that have one of these flags set. Using Eq won't work of course because that will only be true, if that is the only flag set. Solving this using the Criteria API would be the best, but if this is only doable using HQL that is good too.

    Read the article

  • Complex query in nHibernate using DetachedCriteria

    - by paszczi
    Hello! I'm currently trying to move from hand-crafted hql to queries constructed via DetachedCriteria. I have and HQL: from GenericObject genericObject left join fetch genericObject.Positions positions where (positions.Key.TrackedSourceID, positions.Key.PositionTimestamp) in (select gp.Key.TrackedSourceID, max(gp.Key.PositionTimestamp) from GenericPosition gp group by gp.Key.TrackedSourceID) Now using DetachedCriteria: var subquery = DetachedCriteria .For (typeof (GenericPosition), "gp") .SetProjection (Projections.ProjectionList () .Add (Projections.Property ("gp.Key.TrackedSourceID")) .Add (Projections.Max ("gp.Key.PositionTimestamp")) .Add (Projections.GroupProperty ("gp.Key.TrackedSourceID")) ); var criteriaQuery = DetachedCriteria .For (typeof (GenericObject), "genericObject") .CreateAlias ("genericObject.Positions", "positions") .SetFetchMode ("genericObject.Positions", FetchMode.Eager) .Add (Subqueries.In (??, subquery)) I don't know what to type instead of ?? to create expression like (positions.Key.TrackedSourceID, positions.Key.PositionTimestamp)

    Read the article

  • NHibernate, could not load an entity when column exists in the database.

    - by Eitan
    This is probably a simple question to answer but I just can't figure it out. I have a "Company" class with a many-to-one to "Address" which has a many to one to a composite id in "City". When I load a "Company" it loads the "Address", but if I call any property of "Address" I get the error: {"could not load an entity: [IDI.Domain.Entities.Address#2213][SQL: SELECT address0_.AddressId as AddressId13_0_, address0_.Street as Street13_0_, address0_.floor as floor13_0_, address0_.room as room13_0_, address0_.postalcode as postalcode13_0_, address0_.CountryCode as CountryC6_13_0_, address0_.CityName as CityName13_0_ FROM Address address0_ WHERE address0_.AddressId=?]"} The inner exception is: {"Invalid column name 'CountryCode'.\r\nInvalid column name 'CityName'."} What I don't understand is that I can run the query in sql server 2005 and it works, furthermore both those columns exist in the address table. Here are my HBMs: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" > <class name="IDI.Domain.Entities.Company,IDI.Domain" table="Companies"> <id column="CompanyId" name="CompanyId" unsaved-value="0"> <generator class="native"></generator> </id> <property column="Name" name="Name" not-null="true" type="String"></property> <property column="NameEng" name="NameEng" not-null="false" type="String"></property> <property column="Description" name="Description" not-null="false" type="String"></property> <property column="DescriptionEng" name="DescriptionEng" not-null="false" type="String"></property> <many-to-one name="Address" column="AddressId" not-null="false" cascade="save-update" class="IDI.Domain.Entities.Address,IDI.Domain"></many-to-one> <property column="Telephone" name="Telephone" not-null="false" type="String"></property> <property column="TelephoneTwo" name="TelephoneTwo" not-null="false" type="String"></property> <property column="Fax" name="Fax" not-null="false" type="String"></property> <property column="ContactMan" name="ContactMan" not-null="false" type="String"></property> <property column="ContactManEng" name="ContactManEng" not-null="false" type="String"></property> <property column="Email" name="Email" not-null="false" type="String"></property> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" > <class name="IDI.Domain.Entities.Address,IDI.Domain" table="Address"> <id name="AddressId" column="AddressId" type="Int32"> <generator class="native"></generator> </id> <property name="Street" column="Street" not-null="false" type="String"></property> <property name="Floor" column="floor" not-null="false" type="Int32"></property> <property name="Room" column="room" not-null="false" type="Int32"></property> <property name="PostalCode" column="postalcode" not-null="false" type="string"></property> <many-to-one class="IDI.Domain.Entities.City,IDI.Domain" name="City" update="false" insert="false"> <column name="CountryCode" sql-type="String" ></column> <column name="CityName" sql-type="String"></column> </many-to-one> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="IDI.Domain" namespace="IDI.Domain.Entities" > <class name="IDI.Domain.Entities.City,IDI.Domain" table="Cities"> <composite-id> <key-many-to-one class="IDI.Domain.Entities.Country,IDI.Domain" name="CountryCode" column="CountryCode"> </key-many-to-one> <key-property name="Name" column="Name" type="string"></key-property> </composite-id> </class> </hibernate-mapping> Here is my code that calls the Company: IList<BursaUser> user; if(String.IsNullOrEmpty(email) && String.IsNullOrEmpty(company)) return null; ICriteria criteria = Session.CreateCriteria(typeof (BursaUser), "user").CreateCriteria("Company", "comp"); if(String.IsNullOrEmpty(email) || String.IsNullOrEmpty(company) ) { user = String.IsNullOrEmpty(email) ? criteria.Add(Expression.Eq("comp.Name", company)).List<BursaUser>() : criteria.Add(Expression.Eq("user.Email", email)).List<BursaUser>(); } And finally here is where i get the error: "user" was already initialized with the code above: if (user.Company.Address.City == null) user.Company.Address.City = new City(); Thanks.

    Read the article

  • Handling Model Inheritance in ASP.NET MVC2 & NHibernate

    - by enth
    I've gotten myself stuck on how to handle inheritance in my model when it comes to my controllers/views. Basic Model: public class Procedure : Entity { public Procedure() { } public int Id { get; set; } public DateTime ProcedureDate { get; set; } public ProcedureType Type { get; set; } } public ProcedureA : Procedure { public double VariableA { get; set; } public int VariableB { get; set; } public int Total { get; set; } } public ProcedureB : Procedure { public int Score { get; set; } } etc... many of different procedures eventually. So, I do things like list all the procedures: public class ProcedureController : Controller { public virtual ActionResult List() { IEnumerable<Procedure> procedures = _repository.GetAll(); return View(procedures); } } but now I'm kinda stuck. Basically, from the list page, I need to link to pages where the specific subclass details can be viewed/edited and I'm not sure what the best strategy is. I thought I could add an action on the ProcedureController that would conjure up the right subclass by dynamically figuring out what repository to use and loading the subclass to pass to the view. I had to store the class in the ProcedureType object. I had to create/implement a non-generic IRepository since I can't dynamically cast to a generic one. public virtual ActionResult Details(int procedureID) { Procedure procedure = _repository.GetById(procedureID, false); string className = procedure.Type.Class; Type type = Type.GetType(className, true); Type repositoryType = typeof (IRepository<>).MakeGenericType(type); var repository = (IRepository)DependencyRegistrar.Resolve(repositoryType); Entity procedure = repository.GetById(procedureID, false); return View(procedure); } I haven't even started sorting out how the view is going to determine which partial to load to display the subclass details. I'm wondering if this is a good approach? This makes determining the URL easy. It makes reusing the Procedure display code easy. Another approach is specific controllers for each subclass. It simplifies the controller code, but also means many simple controllers for the many procedure subclasses. Can work out the shared Procedure details with a partial view. How to get to construct the URL to get to the controller/action in the first place? Time to not think about it. Hopefully someone can show me the light. Thanks in advance.

    Read the article

  • Nhibernate Criteria Group By clause and select other data that is not grouped

    - by Peter R
    Hi, I have a parent child relationship, let's say class and children. Each child belongs to a class and has a grade. I need to select the children (or the ids of the children) with the lowest grade per class. session.CreateCriteria(typeof(Classs)) .CreateAlias("Children", "children") .SetProjection(Projections.ProjectionList() .Add(Projections.Min("children.Grade")) .Add(Projections.GroupProperty("Id")) ) .List<Object[]>(); This query returns me the lowest grade per class, but I don't know which child got the grade. When I add the children's Id to the group, the group is wrong and every child gets returned. I was hoping we could just select get the id's of those childs without grouping them. If this is not possible, then maybe there is a way to solve this with subqueries?

    Read the article

  • FluentNHibernate SQL Server 2005/2008 Setup Tutorial

    - by Abe
    Hello! Does anybody know of any good tutorials that show how to configure FluentNhibernate for SQL Server 2005/2008. The ones I have found usually just use SQLite, but I would like to see one that specifically targets SQL Server 2005/2008. I really liked the sample tutorial on the FluentNhibernate website (http://wiki.fluentnhibernate.org/Getting_started#Your_first_project), but it looks like most tutorials I have found seem to only deal with SQLite. It would be great to see a working tutorial that deals with the more common databases in real world applications like SQL Server 2005/2008, MySQL, etc Thanks!

    Read the article

  • How is Entity Framework 4's POCO support compared to NHibernate?

    - by Kevin Pang
    Just wondering if anyone has had any experience using Entity Framework 4's POCO support and how it stands up compared to NHibernate. If they're the same, I'd be very interested in making Entity Framework 4 my ORM of choice if only because it would: Support both data first AND object first development Have a robust LINQ provider Be easier to pitch to clients (since it's developed by Microsoft) Come baked into the .NET framework rather than requiring 8 dlls to get up and running In other words, are there any major shortcomings to EF4? Does it support all of the basic functionality NHibernate supports (lazy-loading, eager-loading, 1st level caching, etc.) or is it still rough around the edges? Is the syntax for setting up the mappings as easy as NHibernate and/or Fluent NHibernate? Edit: Please don't bring up the vote of no confidence. That was ages ago and dealt with some serious shortcomings of EF1 that really don't seem to apply anymore to EF4.

    Read the article

  • NHibernate: How to save list in the database?

    - by Anry
    I have a table Order, Transaction, Payment. Class Order has the properties: public virtual Guid Id { get; set; } public virtual DateTime Created { get; set; } ... I added properties: public virtual IList<Transaction> Transactions { get; set; } public virtual IList<Payment> Payments { get; set; } These properties contain a record of tables [Transaction] and [Payment]. How to keep these lists in the database?

    Read the article

  • Nh.Burrow with WCF

    - by Jochen
    Hello, After implementing Nh.Burrow in an asp.net application, I was wondering how to do it for a WCF-service. My first idea was to put a the BurrowFramework().InitWorkSpace(); in each method and set the InstanceContextMode to per Call on these methods. Now I have two questions: Are there better methods to combine Nh.Burrow with WCF? Is there a way to create and use a Long Burrow Conversation with WCF? Regards, Jochen

    Read the article

  • Nhibernate: distinct results in second level Collection

    - by Miguel Marques
    I have an object model like this: class EntityA { ... IList<EntityB> BList; ... } class EntityB { ... IList<EntityC> CList; } I have to fetch all the colelctions (Blist in EntityA and CList in EntityB), because if they all will be needed to make some operations, if i don't eager load them i will have the select n+1 problem. So the query was this: select a from EntityA a left join fetch a.BList b left join fetch b.CList c The fist problem i faced with this query, was the return of duplicates from the DB, i had EntityA duplicates, because of the left join fetch with BList. A quick read through the hibernate documentation and there were some solutions, first i tried the distinct keyword that supposelly wouldn't replicate the SQL distinct keyword except in some cases, maybe this was one of those cases because i had a SQL error saying that i cannot select distict text columns (column [Observations] in EntityA table). So i used one of the other solutions: query.SetResultTransformer(new DistinctRootEntityResultTransformer()); This worked fine. But the result of the operations were still not passing the tests. I checked further and i found out that now there were duplicates of EntityB, because of the left join fetch with CList. The question is, how can i use the distinct in a second level collection? I searched and i only find solutions for the root entity's direct child collection, but never for the second level child collections... Thank you for your time

    Read the article

  • Cascade Saves with Fluent NHibernate AutoMapping - Old Anwser Still Valid?

    - by Glenn
    I want to do exactly what this question asks: http://stackoverflow.com/questions/586888/cascade-saves-with-fluent-nhibernate-automapping Using Fluent Nhibernate Mappings to turn on "cascade" globally once for all classes and relation types using one call rather than setting it for each mapping individually. The answer to the earlier question looks great, but I'm afraid that the Fluent Nhibernate API altered its .WithConvention syntax last year and broke the answer... either that or I'm missing something. I keep getting a bunch of name space not found errors relating to the IOneToOnePart, IManyToOnePart and all their variations: "The type or namespace name 'IOneToOnePart' could not be found (are you missing a using directive or an assembly reference?)" I've tried the official example dll's, the RTM dll's and the latest build and none of them seem to make VS 2008 see the required namespace. The second problem is that I want to use the class with my AutoPersistenceModel but I'm not sure where to this line: .ConventionDiscovery.AddFromAssemblyOf() in my factory creation method. private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database(SQLiteConfiguration.Standard.UsingFile(DbFile)) .Mappings(m => m.AutoMappings .Add(AutoMap.AssemblyOf<Shelf>(type => type.Namespace.EndsWith("Entities")) .Override<Shelf>(map => { map.HasManyToMany(x => x.Products).Cascade.All(); }) ) )//emd mappings .ExposeConfiguration(BuildSchema) .BuildSessionFactory();//finalizes the whole thing to send back. } Below is the class and using statements I'm trying using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using FluentNHibernate.Conventions; using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using NHibernate; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; using FluentNHibernate.Mapping; namespace TestCode { public class CascadeAll : IHasOneConvention, IHasManyConvention, IReferenceConvention { public bool Accept(IOneToOnePart target) { return true; } public void Apply(IOneToOnePart target) { target.Cascade.All(); } public bool Accept(IOneToManyPart target) { return true; } public void Apply(IOneToManyPart target) { target.Cascade.All(); } public bool Accept(IManyToOnePart target) { return true; } public void Apply(IManyToOnePart target) { target.Cascade.All(); } } }

    Read the article

  • Upper extension method in linq to NHibernate

    - by Daniel
    I would like to use the Upper extension method which is declared on the IDbMethods interface against Sql Server 2008. I understand that this will translate to UPPER() on sql server. However I can not figure out how to get an implementation of IDbMethods so that I can use the extension method.

    Read the article

  • Nhibernate many to many criteria query with subselect

    - by Max
    I have a simple example of a blog: a Post table, a Tag table and a Post_Tag_MM lookup table linking the two tables. I use this hql query in order to fetch all posts, that DONT have some tags: var result = session .CreateQuery(@" select p from Post p join p.Tags t where (select count(ti) from p.Tags ti where ti.Uid in (:uidList)) = 0 ") .SetParameterList("uidList", uidList) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .List<Post>(); How can this many-to-many query and the subselect translated into a criteria query? I dont quite understand the DetachedCriteria API yet and could not get it to return the right resultset. Thank you very much in advance. Regards, Max

    Read the article

  • Nhibernate HQL Subselect queries

    - by MegaByte
    Hi I have the following SQL query: select c.id from (select id from customers) c This query has no practical value - I simplified it greatly for the purpose of this post. My question: is it possible have a subquery in the from clause using HQL. If not, can I perhaps query the customers first, kinda like a temp table in sql, and then use the result as the source of the next query? thanks

    Read the article

  • Cannot Cache NHibernate Future Criteria Results

    - by Emilian
    I have the following code: public void FuturesQuery() { using (var session = SessionFactory.OpenSession()) { var blogs = session.CreateCriteria<Blog>() .SetMaxResults(5) .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("BlogQuery") .Future<Blog>(); var countOfBlogs = session.CreateCriteria<Blog>() .SetProjection(Projections.Count(Projections.Id())) .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("BlogQuery") .FutureValue<int>(); Console.WriteLine("Number of blogs: {0}", countOfBlogs.Value); foreach (var blog in blogs) { Console.WriteLine(blog.Title); } } using (var session = SessionFactory.OpenSession()) { var blogs = session.CreateCriteria<Blog>() .SetMaxResults(5) .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("BlogQuery") .Future<Blog>(); var countOfBlogs = session.CreateCriteria<Blog>() .SetProjection(Projections.Count(Projections.Id())) .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("BlogQuery") .FutureValue<int>(); Console.WriteLine("Number of blogs: {0}", countOfBlogs.Value); foreach (var blog in blogs) { Console.WriteLine(blog.Title); } } } I was expecting that the second time I query for blogs and count of blogs I will get values from cache but instead the queries hit the database. If I don't use Futures I get the expected results. Does this means that results from Criteria using futures cannot be cached?

    Read the article

  • Nhibernate , collections and compositeid

    - by Ciaran
    Hi, banging my head here and thought that some one out there might be able to help. Have Tables below. Bucket( bucketId smallint (PK) name varchar(50) ) BucketUser( UserId varchar(10) (PK) bucketId smallint (PK) ) The composite key is not the problem thats ok I know how to get around this but I want my bucket class to contanin a IList of BucketUser. I read the online reference and thought that I had cracked it but havent. The two mappings are below -- bucket -- <id name="BucketId" column="BucketId" type="Int16" unsaved-value="0"> <generator class="native"/> </id> <property column="BucketName" type="String" name="BucketName"/> <bag name="Users" table="BucketUser" inverse="true" generic="true" lazy="true"> <key> <column name="BucketId" sql-type="smallint"/> <column name="UserId" sql-type="varchar"/> </key> <one-to-many class="Bucket,Impact.Dice.Core" not-found="ignore"/> </bag> -- bucketUser --

    Read the article

  • NHibernate: Many-to-many relationship with field in the relationship table

    - by Fossmo
    I'm scratching my head; I have a Car table and a Customer table that have a many-to-many relationship. In this relationship table I want to add a column that can tell me what kind of relationship this is; is the customer testdriving the car, do he want to buy the car, ect. What I want to end up with is a class Car object that holds a collection of Customers and the relationship information. I might be looking at this the wrong way so feel free to push me in the right direction.

    Read the article

  • NHibernate query CreateCriteria

    - by Jacob
    Is it possible to chose what columns I want in return from Session.CreateCriteria() ? egz.: var x = session.CreateCriteria(); x.CreateAlias("EmployeePosition", "employeePosition"); x.Add(Restrictions.Eq("employeePosition.Name", "Developer")); and is there a way to add something like "select LastName" to avoid downloading the whole row.

    Read the article

  • Why doesn't nHibernate support LIMIT when doing "join fetch"?

    - by HeavyWave
    In nHibernate, if you do an HQL query with "join fetch" to eagerly load a child collection, nHibernate will ignore SetMaxResults and SetFirstResult and try to retrieve every single item from the database. Why? This behavior is specific to HQL, as ICriteria supports eager loading (with an outer join, though) and LIMIT. There are more details here http://www.lesnikowski.com/blog/index.php/nhibernate-ignores-setmaxresults-in-sql/ .

    Read the article

  • LEFT OUTER JOIN in NHibernate with SQL semantics

    - by Yuval
    Hi, Is it possible to use HQL/ICritera to produce a query with the same semantics as the following SQL query: select table1.A, table2.B, count(*) from table1 left join (select table2.parent_id, table2.B from table2 where table2.C = 'Some value') as table2 on table2.parent_id = table1.id group by table1.A, table2.B order by table1.A In particular, what I'd like is to receive rows (that is, objects) from table1 that have no matching rows in table2. However, I only get the rows from table1 that have matches in table2. Is this the meaning of 'LEFT JOIN' in HQL? And if so, how can I get it to join on a subquery? Tnx.

    Read the article

  • Get subclass type from projection with NHibernate

    - by TigerShark
    Hi I am trying to do a projection on a type called Log. Log references a superclass called Company. Each company type is mapped with table per subclass. Is it possible for me to get the type of Company when I do a projection on Log? I currently have an Enum property (which is not mapped) on each subclass, so I can perform switches on Company types, but since it is not mapped to anything, I can't do a projection on it. I have tried Projections.Property("log.Company.class") but that does not work :( PS: I couldn't find a lot of appropriate tags for this question. If anyone have an idea for more specific tags, please tell me.

    Read the article

  • Architecture with NHibernate and Repositories

    - by Matthew
    I've been reading up on MVC 2 and the recommended patterns, so far I've come to the conclusion (amongst much hair pulling and total confusion) that: Model - Is just a basic data container Repository - Provides data access Service - Provides business logic and acts as an API to the Controller The Controller talks to the Service, the Service talks to the Repository and Model. So for example, if I wanted to display a blog post page with its comments, I might do: post = PostService.Get(id); comments = PostService.GetComments(post); Or, would I do: post = PostService.Get(id); comments = post.Comments; If so, where is this being set, from the repository? the problem there being its not lazy loaded.. that's not a huge problem but then say I wanted to list 10 posts with the first 2 comments for each, id have to load the posts then loop and load the comments which becomes messy. All of the example's use "InMemory" repository's for testing and say that including db stuff would be out of scope. But this leaves me with many blanks, so for a start can anyone comment on the above?

    Read the article

< Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >