Search Results

Search found 16665 results on 667 pages for 'nhibernate configuration'.

Page 44/667 | < Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >

  • (N)Hibernate: deleting orphaned ternary association rows when either associated row is deleted.

    - by anthony
    I have a ternary association table created using the following mapping: <map name="Associations" table="FooToBar"> <key column="Foo_id"/> <index-many-to-many class="Bar" column="Bar_id"/> <element column="AssociationValue" /> </map> I have 3 tables, Foo, Bar, and FooToBar. When I delete a row from the Foo table, the associated row (or rows) in FooToBar is automatically deleted. This is good. When I delete a row from the Bar table, the associated row (or rows) in FooToBar remain, with a stale reference to a Bar id that no longer exists. This is bad. How can I modify my hbm.xml to remove stale FooToBar rows when deleting from the Bar table?

    Read the article

  • NHibernate bag is always null

    - by Neville Chinan
    I have set up my mapping file and classes as suggested by many articles class A { ... IList BBag {get;set;} ... } class B { ... A aObject {get;set;} ... } <class name="A">...<bag name="BBag" table="B" inverse="true" lazy="false"><key column="A_ID" /><one-to-many class="B" /></bag>... <class name="B">...<many-to-one name="aObject" class="A" column="A_ID" />... I added a set of A's to the A table and a set of B's to the B table, all the data is stored as expected. However if I try and access aInstance.BBag.Count I get a null reference exception. I think I missing some key knowledge on how an bag gets instantiated. Thanks

    Read the article

  • Fluent Nhibernate expression to select on flagged enum

    - by mbalkema
    I have a domain entity that has a flagged enum as a property. The flagged enum is the target audience for the these entities. The user then has a flagged enum value of the entities they should see. I am trying to figure out the correct expression to select entities that meet the target audience for the user. public class File { public virtual TargetAudience TargetAudience { get; set; } } [Flags] public enum TargetAudience { Audience1 = 1, Audience2 = 2, Audience3 = 4, Audience4 = 8 } Expression: (This works when performed on a IList<File>, but doesn't work on a query to the database.) public Expression<Func<File, bool>> Expression { get { return ((x.TargetAudience & UserTargetedAudience) > 0); } } Any suggestions would be helpful.

    Read the article

  • nHibernate one-to-many inserts but doesnt update

    - by user210713
    Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has anyone ever had a one-to-many where the child object gets inserted but not updated resulting in a row in my table with a null in the foreign key column? I want the default behaviour for a standard one-to-many. I don't want to have to add the parent as a property to the child. Thanks.

    Read the article

  • NHibernate Overcoming NotSupportedException

    - by Jordan Wallwork
    Does anyone know of any way to overcome NotSupportedException? I have a method against a User: public virtual bool IsAbove(User otherUser) { return HeirarchyString.StartsWith(otherUser.HeirarchyString); } And I want to do: _session.Query<User>.Where(x => loggedInUser.IsAbove(x)); But this throws a NotSupportedException. The real pain though is that using _session.Query<User>.Where(x => loggedInUser.HeirarchyString.StartsWith(x.HeirarchyString)); works absolutely fine. I don't like this as a solution, however, because it means that if I change how the IsAbove method works, I have to remember all the places where I have duplicated the code whenever I want to update it

    Read the article

  • NHibernate filters don't work with Session.Get

    - by Khash
    I'm trying to implement a Soft-deletable repository. Usually this can be easily done with a Delete Event listener. To filter out the deleted entities, I can add a Where attribute to my class mapping. However, I also need to implement two more methods in the repository for this entity: Restore and Purge. Restore will "undelete" entities and Purge will hard-delete them. This means I can't use Where attribute (since it block out soft-deleted entities to any access) I tried using filters instead. I can create a filter and enable or disable it within session to achieve the same result. But the problem is filters don't have any effect on Session.Get method (they only affect ICriteria based access). Any ideas as to how solve this problem? Thanks

    Read the article

  • Nhibernate Left Outer Join Return First Record of the Join

    - by Touch
    I have the following mappings of which Im trying to bring back 0 - 1 Media Id associated with a Product using a left join (I havnt included my attempt as it confuses the situation) ICriteria productCriteria = Session.CreateCriteria(typeof(Product)); productCriteria .CreateAlias("ProductCategories", "pc", JoinType.InnerJoin) .CreateAlias("pc.ParentCategory", "category") .CreateAlias("category.ParentCategory", "group") .Add(Restrictions.Eq("group.Id", 333)) .SetProjection( Projections.Distinct( Projections.ProjectionList() .Add(Projections.Alias(Projections.Property("Id"), "Id")) .Add(Projections.Alias(Projections.Property("Title"), "Title")) .Add(Projections.Alias(Projections.Property("Price"), "Price")) .Add(Projections.Alias(Projections.Property("media.Id"), "SearchResultMediaId")) // I NEED THIS ) ) .SetResultTransformer(Transformers.AliasToBean<Product>()); IList<Product> products = productCriteria .SetFirstResult(0) .SetMaxResults(10) .List<Product>(); I need the query to populate the SearchResultMediaId with Media.Id, I only want to bring back the first Media in a left outer join, as this is 1 to many association between Product and Media Product is mapped to Media in the following way mapping.HasManyToMany<Media>(x => x.Medias) .Table("ProductMedias") .ParentKeyColumn("ProductId") .ChildKeyColumn("MediaId") .Cascade.AllDeleteOrphan() .LazyLoad() .AsBag(); Any Help would be fantastic.

    Read the article

  • Query regarding the Nhibernate many to many mapping

    - by Pramod
    Hi, I have a requirement where i have 3 dimension tables (employee, project, technology) and a common fact table which has the key id's of all these three tables. My question goes like this... How do i create a mapping table (fact table) having these three columns - emp_id, proj_i and tech_i. I know we can achieve this for two tables using the below syntax: HasManyToMany(x = x.Empl) .Table("Emp_Proj") .ParentKeyColumn("Emp_i") .ChildKeyColumn("Proj_I") .Inverse() .Cascade.All(); How can i add another child key column (tech_i) to the above mapping table?

    Read the article

  • NHibernate collections: many-to-many relationships

    - by Brad Heller
    I've got two models, a Product model and a ShoppingCart model. The ShoppingCart model has a collection of products as a property called Products (List). Here is the mapping for my ShoppingCart model. <class name="MyProject.ShoppingCart, MyProject" table="ShoppingCarts"> <id name="Id" column="Id"> <generator class="native" /> </id> <many-to-one name="Company" class="MyProject.Company, MyProject" column="CompanyId" /> <property name="ExternalId" column="GUID" generated="insert" /> <property name="Name" column="Name" /> <property name="Total" column="Total" /> <property name="CreationDate" column="CreationDate" generated="insert" /> <property name="UpdatedDate" column="UpdatedDate" generated="always" /> <bag name="Products" table="ShoppingCartContents" lazy="false"> <key column="ShoppingCartId" /> <many-to-many column="ProductId" class="MyProjectMyProject.Product, MyProject" fetch="join" /> </bag> </class> When I try to save to the DB, the ShoppingCart is saved, but the mapping rows in ShoppingCartContents aren't save, making me thing that there's an issue with the mapping. Where am I going wrong here?

    Read the article

  • How do I setup a Criteria in nHibernate to query against multiple values

    - by AWC
    I want to query for a set of results based on the contents of a list, I've managed to do this for a single instance of the class Foo, but I'm unsure how I would do this for a IList<Foo>. So for a single instance of the class Foo, this works: public ICriteria CreateCriteria(IList<Foo> foo) { return session .CreateCriteria<Component>() .CreateCriteria("Versions") .CreateCriteria("PublishedEvents") .Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere), Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere))) .SetCacheable(true); } But how do I do this when the method parameter is a list of Foo? public ICriteria CreateCriteria(IList<Foo> foos) { return session .CreateCriteria<Component>() .CreateCriteria("Versions") .CreateCriteria("PublishedEvents") .Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere), Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere))) .SetCacheable(true); }

    Read the article

  • Mapping child objects in fluent nhibernate to a read-only view

    - by grenade
    Given that I am implementing a read-only UI, how do I create a ClassMap for Shop: public class Shop { public int Id { get; set; } public City City { get; set; } } public class City { public string Name { get; set; } public string CountryCode { get; set; } } The DB interface for Shops is a View containing 3 columns (ShopId, CityName, CountryCode). I was hoping to do something like this: public sealed class ShopMap : ClassMap<Shop> { public ShopMap() { Table("Shop"); Id(x => x.Id, "ShopId"); Map(x => x.City.Name, "CityName"); Map(x => x.City.CountryCode, "CountryCode"); } } Will fluent auto-instantiate Shop.City?

    Read the article

  • NHibernate listener/event to replace object before insert/update

    - by vIceBerg
    Hi! I have a Company class which have a collection of Address. Here's my Address class:(written top of my head): public class Address { public string Civic; public string Street; public City City; } This is the City class: public class City { public int Id; public string Name; public string SearchableName{ get { //code } } } Address is persisted in his own table and have a reference to the city's ID. City are also persisted in is own table. The City's SearchableName is used to prevent some mistakes in the city the user type. For example, if the city name is "Montréal", the searchable name will be "montreal". If the city name is "St. John", the searchable name will be "stjohn", etc. It's used mainly to to search and to prevent having multiple cities with a typo in it. When I save an address, I want an listener/event to check if the city is already in the database. If so, cancel the insert and replace the user's city with the database one. I would like the same behavior with updates. I tried this: public bool OnPreInsert(PreInsertEvent @event) { City entity = (@event.Entity as City); if (entity != null) { if (entity.Id == 0) { var city = (from c in @event.Session.Linq<City>() where c.SearchableName == entity.SearchableName select c).SingleOrDefault(); if (city != null) { //don't know what to do here return true; } } } return false; } But if there's already a City in the database, I don't know what to do. @event.Entity is readonly, if I set @event.Entity.Id, I get an "null identifier" exception. I tried to trap insert/update on Address and on Company, but the City if the first one to get inserted (it's logic...) Any thoughts? Thanks

    Read the article

  • Mapping an Array to a Single Row

    - by João Bragança
    I have the following classes: public class InventoryItem { private Usage[] usages = new Usage[12]; virtual public Usage[] Usages { get { return usages; }} virtual public string Name{get;set;} } public class Usage { virtual public double Quantity{get;set;} virtual public string SomethingElse{get;set;} } I know that Usages.Length will always be 12. I think it would be best to store it in the DB like so: Name nvarchar(64), Usage_Quantity_0 float, Usage_SomethingElse_0 nvarchar(16), Usage_Quantity_1 float, Usage_SomethingElse_1 nvarchar(16), ... Usage_Quantity_11 float, Usage_SomethingElse_11 nvarchar(16), How can I get this done?

    Read the article

  • NHibernate - EventListener for SaveOrUpdateCopy

    - by t-kehl
    Hi. I do Update with SaveOrUpdateCopy(). Now, I have attached an event for this: this.EventListeners.SaveOrUpdateCopyEventListeners = new IMergeEventListener[] { new AuditableSaveOrUpdateCopyEventListener() }; In the AuditableSaveOrUpdateCopyEventListener, I have inherited from DefaultSaveOrUpdateCopyEventListener and overriden OnMerge(): public class AuditableSaveOrUpdateCopyEventListener : DefaultSaveOrUpdateCopyEventListener { public override void OnMerge(MergeEvent evt) { this.AddAuditableData(evt); base.OnMerge(evt); } public override void OnMerge(MergeEvent evt, System.Collections.IDictionary copyCache) { this.AddAuditableData(evt); base.OnMerge(evt, copyCache); } private void AddAuditableData(MergeEvent evt) { var entity = evt.Original as AuditableEntityBase; if (entity != null) { ... } } } But when I now change properties in entity, they will not be saved to the database. Can someone give me a tip, how I can add my auditable-data for SaveOrUpdateCopy? Thank you. Best Regards, Thomas

    Read the article

  • NHibernate Criteria question

    - by Jeneatte Jolie
    I have a person object, which can have unlimited number of first names. So the first names are another object. ie person --- name             --- name             --- name What I want to do is write an nhiberate query using which will get me a person who has certain names. so one query might be find someone whose names are alison and jane and philippa, then next query may be one to find someone whose names are alison and jane. I only want to return people who have all the names I'm search on. So far I've got ICriteria criteria = session.CreateCriteria(typeof (Person)); criteria.CreateAlias("Names", "name"); ICriterion expression = null; foreach (string name in namesToFind) { if (expression == null) { expression = Expression.Like("name.Value", "%" + name + "%"); } else { expression = Expression.Or( expression, Expression.Like("name.Value", "%" + name + "%")); } } if (expression != null) criteria.Add(expression); But this is returning every person with ANY of the names I'm searching on, not ALL the names. Can anyone help me out with this? Thanks!

    Read the article

  • Need help configuring SQL Server CE connections string in Fluent NHibernate

    - by Yoav
    Hi, I'm trying to return a session factory using this code: return Fluently.Configure() .Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(path)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Project>()) .BuildSessionFactory(); Path is the full path to an .sdf file. And get this exception: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. at System.Data.SqlServerCe.ConStringUtil.GetKeyValuePair(Char[] connectionString, Int32 currentPosition, String& key, Char[] valuebuf, Int32& vallength, Boolean& isempty) What am I doing wrong?

    Read the article

  • How to integrate Windows Azure, Spring.NET and NHibernate?

    - by paologios
    Hi, we have a ASP.NET web application which makes use of NHibernate and Spring.NET (to do the session and transaction management stuff). Now we want to port parts of it to a Windows Azure application without making lots of changes to the used components. I already found this article of stackoverflow so I hope to get NHibernate running on Azure. My question: Has anybody experiences in running Spring.NET on Azure (with or without NHibernate) ??

    Read the article

  • NHibernate 'IdentifierGenerationException' on an Update trigger

    - by Jan Jongboom
    In my database I have an id column defined as [autonumber] [int] IDENTITY(1,1) NOT NULL which is mapped in my .hbm.xml like: <id name="Id" column="autonumber" type="int"> <generator class="identity" /> </id> When calling session.Save() updates are successful committed to the database. When adding a versioning trigger I however get the error this id generator generates Int64, Int32, Int16 of type IdentifierGenerationException. The trigger is defined as: ALTER TRIGGER [dbo].[CatchUpdates_NVM_FDK_Kenmerken] ON [dbo].[NVM_FDK_Kenmerken] INSTEAD OF UPDATE AS BEGIN SET NOCOUNT ON UPDATE NVM_FDK_Kenmerken SET idIsActive = 0 WHERE internalId IN (SELECT internalId FROM INSERTED) INSERT INTO dbo.NVM_FDK_Kenmerken ( vestigingNummer , internalId , someOtherColumns, dateInserted, idIsActive ) SELECT vestigingNummer, internalId, someOtherColumns, GETDATE(), 1 FROM INSERTED END What am I doing wrong here? When doing manual updates everything works just fine and as expected.

    Read the article

  • nHibernate criteria - how do I implement 'having count'

    - by AWC
    I have the following table structure and I want a turn the query into a NH criteria but I'm not sure how to incorporate the correct 'Projection', does anyone know how? And the query I want to turn into a Criteria: select ComponentId from Table_1 where [Name] = 'Contact' or [Name] = 'CurrencyPair' group by ComponentId having count(VersionId) = 2

    Read the article

  • NHibernate LINQ + PLINQ

    - by cvista
    Hi i've just started reading up on PLINQ and find it fasinating. I'm using NHib-Linq in my projects - does anyone know if there's any benefit/problems using PLINQ type queries with NHLinq? w://

    Read the article

  • Left Outer Join on Many-to-One Mapping

    - by Colin Bowern
    I have a reference to call that may or may not be there. When I add the nullable option it still doing Inner Join when I want an Outer Left Join (show the left even if the right is null). Is this possible in the NH map? References(x => x.DefaultCategory, "CATEGORY_ID") .Nullable();

    Read the article

  • Handling user security scope with nHibernate or other ORM

    - by Schotime
    How should one handle the situation where you may need to filter by a group of users. Here is the scenario. I have an administrator role in my company. I should be able to see all the data belonging to me plus all the other users who I have control over. A plain old user however should only be able to access their own data. If you are writing regular sql statements then you can have a security table with every user and who they have access too but i'm not sure how to handle this situation in the OO and ORM world. Any one dealt with this scenario in a web application using an ORM? Would love to hear your thoughts!

    Read the article

  • Delete only reference to child object

    - by Al
    I'm running in to a bit of a problem where any attempt to delete just the reference to a child also deletes the child record. My schema looks like this Person Organisation OrganisationContacts : Person OrgId PersonId Role When removing an Organisation i want to only delete the record in OrgnaisationContacts, but not touch the Person record. My Mapping looks like this Code: public OrganisationMap() { Table("Organsations"); .... HasMany<OrganisationContact>(x => x.Contacts) .Table("OrganisationContacts ") .KeyColumn("OrgId") .Not.Inverse() .Cascade.AllDeleteOrphan(); } public class OrganisationContactMap : SubclassMap<OrganisationContact> { public OrganisationContactMap() { Table("OrganisationContacts"); Map(x => x.Role, "PersonRole"); Map(x => x.IsPrimary); } } At the moment just removing a contact from the IList either doesn't reflect in the database at all, or it issues two delete statements DELETE FROM OrganisationContact & DELETE FROM Person, or tries to set PersonId to null in the OrganisationContacts table. All of which are not desirable. Any help would be great appreciated.

    Read the article

< Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >