Search Results

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

Page 10/132 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • NHibernate parent-childs save redundant sql update executed

    - by Broken Pipe
    I'm trying to save (insert) parent object with a collection of child objects, all objects are new. I prefer to manually specify what to save\update and when so I do not use any cascade saves in mappings and flush sessions by myself. So basically I save this object graph like: session.Save(Parent) foreach (var child in Parent.Childs) { session.Save(child); } session.Flush() I expect this code to insert Parent row, then each child row, however NHibernate executes this SQL: INSERT INTO PARENT.... INSERT INTO CHILD .... UPDATE CHILD SET ParentId=@1 WHERE Id=@2 This update statement is absolutely unnecessary, ParentId was already set correctly in INSERT. How do I get rid of it? Performance is very important for me.

    Read the article

  • Linq to NHibernate - How to return a parent object with only certain child objects included

    - by vakman
    Given a simplified model like the following: public class Enquiry { public virtual DateTime Created { get; set; } public virtual Sender Sender { get; set; } } public class Sender { public virtual IList<Enquiry> Enquiries { get; set; } } How can you construct a Linq to Nhibernate query such that it gives you back a list of senders and their enquiries where the enquiries meet some criteria. I have tried something like this: return session.Linq<Enquiry>() .Where(enquiry => enquiry.Created < DateTime.Now) .Select(enquiry => enquiry.Sender) In this case I get an InvalidCastException saying you can't cast type Sender to type Enquiry. Any pointers on how I can do this without using HQL?

    Read the article

  • Linq to NHibernate - How to include parent object and only certain child objects

    - by vakman
    Given a simplified model like the following: public class Enquiry { public virtual DateTime Created { get; set; } public virtual Sender Sender { get; set; } } public class Sender { public virtual IList<Enquiry> Enquiries { get; set; } } How can you construct a Linq to Nhibernate query such that it gives you back a list of senders and their enquiries where the enquiries meet some criteria. I have tried something like this: return session.Linq<Enquiry>() .Where(enquiry => enquiry.Created < DateTime.Now) .Select(enquiry => enquiry.Sender) In this case I get an InvalidCastException saying you can't cast type Sender to type Enquiry. Any pointers on how I can do this without using HQL?

    Read the article

  • Rethinking Oracle Optimizer Statistics for P6 Part 2

    - by Brian Diehl
    In the previous post (Part 1), I tried to draw some key insights about the relationship between P6 and Oracle Optimizer Statistics.  The first is that average cardinality has the greatest impact on query optimization and that the particular queries generated by P6 are more likely to use this average during calculations. The second is that these are statistics that are unlikely to change greatly over the life of the application. Ultimately, our goal is to get the best query optimization possible.  Or is it? Stability No application administrator wants to get the call at 9am that their application users cannot get there work done because everything is running slow. This is a possibility with a regularly scheduled nightly collection of statistics. It may not just be slow performance, but a complete loss of service because one or more queries are optimized poorly. Ideally, this should not be the case. The database optimizer should make better decisions with more up-to-date data. Better statistics may give incremental performance benefit. However, this benefit must be balanced against the potential cost of system down time.  It is stability that we ultimately desire and not absolute optimal performance. We do want the benefit from more accurate statistics and better query plans, but not at the risk of an unusable system. As a result, I've developed the following methodology around managing database statistics for the P6 database.  1. No Automatic Re-Gathering - The daily, weekly, or other interval of statistic gathering is unlikely to be beneficial. Quite the opposite. It is more likely to cause problems. 2. Smart Re-Gathering - The time to collect statistics is when things have changed significantly. For a new installation of P6, this is happening more often because the data is growing from a few rows to thousands and more. But for a mature system, the data is not changing significantly from week-to-week. There are times to collect statistics: New releases of the application Changes in the underlying hardware or software versions (ex. new Oracle RDBMS version) When additional user groups are added. The new groups may use the software in significantly different ways. After significant changes in the data. This may be monthly, quarterly or yearly.  3. Always Test - If you take away one thing from this post, it would be to always have a plan to test after changing statistics. In reality, statistics can be collected as often as you desire provided there are tests in place to verify that performance is the same or better. These might be automated tests or simply a manual script of application functions. 4. Have a Way Out - Never change the statistics without a way to return to the previous set. Think of the statistics as one part of the overall application code that also includes the source code--both application and RDBMS. It would be foolish to change to the new code without a way to get back to the previous version. In the final post, I will talk about the actual script I created for P6 PMDB and possible future direction for managing query performance. 

    Read the article

  • Cascading items in a collection of a component

    - by mattcole
    I have a component which contains a collection. I can't seem to get NHibernate to persist items in the collection if I have the collection marked as Inverse. They will persist if I don't have Inverse on the collection, but I get an insert and then an update statement. My mapping is : m => m.Component(x => x.Configuration, c => { c.HasMany(x => x.ObjectiveTitleTemplates) .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore) .AsSet() //.Inverse() .KeyColumns.Add("ObjectiveProcessInstanceId") .Cascade.AllDeleteOrphan(); }); Is there a way to get it working marking the collection as Inverse and therefore avoiding the extra insert? Thanks!

    Read the article

  • Getting \ building latest NHibernate build

    - by Alex Yakunin
    I'd like to get the latest NHibernate build or build it by my own. The build available at SourceForge is dated by Nov 2009, although I see there was a lot of activity later, especially related to LINQ development. So what is the best option? I can: Get the latest source code and try to build it. Are there any instructions for this? Get one of latest builds shared by someone else. Are there any people maintaining such builds? Please note, that I'm not interested in 8-month old builds - I need the latest code for tests (LINQ, performance). I know there is a similar question, but it looks like top answers there are outdated.

    Read the article

  • how to map SubclassMap and HasManyToMany in Fluent NHibernate

    - by Davide Orazio Montersino
    Hi everyone. My problem is fluent nhibernate mapping a many to many relationship, they end up referencing a non existent Id. public UserMap() { Id(x => x.Id); Map(x => x.Name); Map(x => x.Password); Map(x => x.Confirmed); HasMany(x => x.Nodes).Cascade.SaveUpdate(); HasManyToMany<Node>(x => x.Events).Cascade.SaveUpdate().Table("RSVPs"); } public EventMap() { Map(x => x.Starts); Map(x => x.Ends); HasManyToMany<User>(x => x.Rsvps).Cascade.SaveUpdate().Table("RSVPs"); } public NodeMap() { Id(x => x.Id); Map(x => x.Title); Map(x => x.Body).CustomSqlType("text"); Map(x => x.CreationDate); References(x => x.Author).Cascade.SaveUpdate(); Map(x => x.Permalink).Unique().Not.Nullable(); } Those are my classes -notice that Event inherits from Node: public class Event : Node//, IEvent { private DateTime _starts = DateTime.MinValue; private DateTime _ends = DateTime.MaxValue; public virtual IList<User> Rsvps { get; set; } } The problem is, the generated RSVPs table is like that: Event_id User_id Node_id Of course the Event table has no ID - only a Node_id. When trying to save a relationship it will try to save a NULL event_id thus generating an error.

    Read the article

  • NHibernate.PropertyValueException : not-null property references a null or transient

    - by frosty
    I am getting the following exception. NHibernate.PropertyValueException : not-null property references a null or transient Here are my mapping files. Product <class name="Product" table="Products"> <id name="Id" type="Int32" column="Id" unsaved-value="0"> <generator class="identity"/> </id> <set name="PriceBreaks" table="PriceBreaks" generic="true" cascade="all" inverse="true" > <key column="ProductId" /> <one-to-many class="EStore.Domain.Model.PriceBreak, EStore.Domain" /> </set> </class> Price Breaks <class name="PriceBreak" table="PriceBreaks"> <id name="Id" type="Int32" column="Id" unsaved-value="0"> <generator class="identity"/> </id> <property name="ProductId" column="ProductId" type="Int32" not-null="true" /> <many-to-one name="Product" column="ProductId" not-null="true" cascade="all" class="EStore.Domain.Model.Product, EStore.Domain" /> </class> I get the exception on the following method [Test] public void Can_Add_Price_Break() { IPriceBreakRepository repo = new PriceBreakRepository(); var priceBreak = new PriceBreak(); priceBreak.ProductId = 19; repo.Add(priceBreak); Assert.Greater(priceBreak.Id, 0); }

    Read the article

  • fluent nhibernate select n+1 problem

    - by Andrew Bullock
    I have a fairly deep object graph (5-6 nodes), and as I traverse portions of it NHProf is telling me I've got a "Select N+1" problem (which I do). The two solutions I'm aware of are Eager load children Break apart my object graph (and eager load) I don't really want to do either of these (although I may break the graph apart later as I forsee it growing) For now.... Is it possible to tell NHibernate (with fluentnhib) that whenever i try to access children, to load them all in one go, instead of selectn+1ing as i iterate over them? I'm also getting "unbounded results set"s, which is presumably the same problem (or rather, will be solved by the above solution if possible). Each child collection (throughout the graph) will only ever have about 20 members, but 20^5 is a lot, so i dont want to eager load everything when i get the root, but simply get all of a child collection whenever i go near it Edit: an afterthought.... what if i want to introduce paging when i want to render children? do i HAVE to break my object graph here, or is there some sneakyness i can employ to solve all these issues?

    Read the article

  • Fluent NHibernate - Cascade delete a child object when no explicit parent->child relationship exists

    - by John Price
    I've got an application that keeps track of (for the sake of an example) what drinks are available at a given restaurant. My domain model looks like: class Restaurant { public IEnumerable<RestaurantDrink> GetRestaurantDrinks() { ... } //other various properties } class RestaurantDrink { public Restaurant Restaurant { get; set; } public Drink { get; set; } public string DrinkVariety { get; set; } //"fountain drink", "bottled", etc. //other various properties } class Drink { public string Name { get; set; } public string Manufacturer { get; set; } //other various properties } My db schema is (I hope) about what you'd expect; "RestaurantDrinks" is essentially a mapping table between Restaurants and Drinks with some extra properties (like "DrinkVariety" tacked on). Using Fluent NHibernate to set up mappings, I've set up a "HasMany" relationship from Restaurants to RestaurantDrinks that causes the latter to be deleted when its parent Restaurant is deleted. My question is, given that "Drink" does not have any property on it that explicitly references RestaurantDrinks (the relationship only exists in the underlying database), can I set up a mapping that will cause RestaurantDrinks to be deleted if their associated Drink is deleted? Update: I've been trying to set up the mapping from the "RestaurantDrink" end of things using References(x => x.Drink) .Column("DrinkId") .Cascade.All(); But this doesn't seem to work (I still get an FK violation when deleting a Drink).

    Read the article

  • Linq to NHibernate wrapper issue using where statement

    - by Jacob
    I'am using wrapper to get some data from table users IQueryable<StarGuestWrapper> WhereQuery = session.Linq<User>().Where(u => u.HomeClub.Id == clubId && u.IsActive).Select( u => new StarGuestWrapper() { FullName = u.Name + " " + u.LastName, LoginTime = DateTime.Now, MonthsAsMember = 2, StarRating = 1, UserPicture = u.Photo.PhotoData, InstructorFullName = "Someone Xyz", TalkInteractionDuringSession = true, GoalInteractionDuringSession = false }); I use this without a problem as a IQueryable so I can do useful things before actually running the query. Like : WhereQuery.Skip(startRowIndex).Take(maximumRows).ToList(); and so on. The problem occurs using 'where' statement on query. For example: WhereQuery.Where(s => s.StarRating == 1) will throw an exception in runtime that 'StarRating' doesn't exist in User table - of course it doesn't it's a wrappers property. I will work if I materialize query by WhereQuery.AsEnumerable().Where(s => s.StarRating == 1) but then it loses all the sens of using IQueryable and I don't want to do this. What is strange and interesting that not all properties from wrapper throw error, all the bool values can be used in where statement. Example : WhereQuery.Where(s => s.TalkInteractionDuringSession) It works in EntityFramework , why do I get this error in NHibernate and how to get it working the way I want it to ?

    Read the article

  • Castle ActiveRecord / NHibernate Linq Querys with ValueTypes

    - by Thomas Schreiner
    Given the following code for our Active Record Entites and ValueTypes Linq is not working for us. [ActiveRecord("Person")] public class PersonEntity : ActiveRecordLinqBase<PersonEntity> { string _name; [Property("Name", Length = 20, ColumnType = "string", Access = PropertyAccess.FieldCamelcaseUnderscore)] public Name Name { get { return NameValue.Create(_name);} set { _name = value.DataBaseValue; } } ... } public abstract class Name : IValueType { string DataBaseValue {get;set;} ... } public class Namevalue : Name { string _name; private NameValue(string name) { _name = name; } public static NameValue Create(string name) { return new NameValue(name); } ... } We tried to use linq in the following way so far with no success: var result = from PersonEntity p in PersonEntity.Queryable where p.Name == "Thomas" select p; return result.First(); // throws exception Cannot convert string into Name We tried and implemented a TypeConverter for Name, but the converter never got called. Is there a way to have linq working with this ValueTypes? Update: Using NHibernate.UserTypes.IUserType it sortof works. I Implemented the Interface as described here: http://stackoverflow.com/questions/1565056/how-to-implement-correctly-iusertype I still had to add a ConversionOperator from string to Name and had to call it Explicitly in the linq Statement, even though it was defined as implicit. var result = from PersonEntity p in PersonEntity.Queryable where p.Name == (Name)"Thomas" select p; return result.First(); //Now works

    Read the article

  • What would be the equivalent VB.NET code for this C# FluentNHibernate component mapping?

    - by Will Marcouiller
    I'm a C# programmer constrained to write VB.NET code. While exploring NHibernate further for my current client, I encountered FluentNHibernate, which I find real attractive. But now, I wonder how to "translate" this C# code for component mapping into VB.NET code: Component(x => x.Address, m => { m.Map(x => x.Number); m.Map(x => x.Street); m.Map(x => x.PostCode); }); I know from here: Component(Of Client)(Function(c) c.Address, ...) what I miss is how to continue with the brackets in VB.NET, since there's no Begin End keywords or so. EDIT 1: Following Mr. JaredPar instructions, I figured that his solution might work. If we take the time to read his answer, we may notice that we both don't know what the MType is within his solution. I might have found out that the MType is: FluentNHibernate.Mapping.ComponentPart(Of TComponent) Thus, TComponent is, from my understanding, an anonymous type that I shall parameter to use. From this point of view, since I wish to map the properties of my Address object, replacing TComponent in my help method signature seems not to work. Private Sub MapAdresseHelper(Of Adresse)(ByVal a As FluentNHibernate.Mapping.ComponentPart(Of Adresse)) a.Map(Function(m) m.Number) a.Map(Function(m) m.Street).Length(50) a.Map(Function(m) m.PostCode).Length(10) End Sub The error I get is that my Address class doesn't have a property member named Street, for instance. It sees my Address type, it recognizes it, but it seems buggy somehow. I guess VBNET is poorly designed for lambda expressions and is less evolved than C# (Sorry, a bit of frustration due to the constraint of working with it and not being capable of doing things VERY easily done in C#.) Thanks!

    Read the article

  • Nhibernat mapping aspnet_Users table

    - by Michael D. Kirkpatrick
    My User table I want to map to aspnet_Users: <class name="User" table="`User`"> <id name="ID" column="ID" type="Int32" unsaved-value="0"> <generator class="native" /> </id> <property name="UserId" column="UserId" type="Guid" not-null="true" /> <property name="FullName" column="FullName" type="String" not-null="true" /> <property name="PhoneNumber" column="PhoneNumber" type="String" not-null="false" /> </class> My aspnet_Users table: <class name="aspnet_Users" table="aspnet_Users"> <id name="ID" column="UserId" type="Guid" /> <property name="UserName" column="UserName" type="string" not-null="false" /> </class> I tried adding one-to-one, one-to-many and many-to-one mappings. The closest I can get is with this error: Object of type 'System.Guid' cannot be converted to type 'System.Int32'. How do I create a 1 way mapping from User to aspnet_User via the UserId column in User? I am only wanting to create a reference so I can extract read-only information, affect sorts, etc. I still need to leave UserId column in User set up like it is now. Maybe a virtual reference keying off of UserId? Is this even possible with Nhibernate? Unfortunately it acts like it only wants to use ID from User to map to aspnet_Users. Changing the table User to have it's primary key be UserId instead of ID is not an option at this point. Any help would be greatly appreciated. Thanks in advance.

    Read the article

  • nhibernate not taking mappings from assembly

    - by cvista
    Hi I'm using fnh and castle nhib facility. I followed the advice from mike hadlow here: http://mikehadlow.blogspot.com/2009/01/integrating-fluent-nhibernate-and.html here is my FluentNHibernateConfigurationBuilder: public Configuration GetConfiguration(IConfiguration facilityConfiguration) { var defaultConfigurationBuilder = new DefaultConfigurationBuilder(); var configuration = defaultConfigurationBuilder.GetConfiguration(facilityConfiguration); configuration.AddMappingsFromAssembly(typeof(User).Assembly); return configuration; } i know the facility is picking it up as i can break inside that method and it steps through. however, when it's done, non of the mappings are created and i get the following error when i try to save an entity: No persister for: IsItGd.Model.Entities.User here is my user class: //simple model of web user public class User { public virtual int Id { get; set; } public virtual string FullName { get; set; } } and here is the mapping: public class UserMap : ClassMap<User> { public UserMap() { Id(x=>x.Id); Map(x=>x.FullName); } } i really can't see what the problem is. the strange thing is - is that if i use automapping it picks everything up - but i don't want to use automapping as i can't do certain things in that scenario. any clues? w://

    Read the article

  • Will the following NHibernate interface mapping work?

    - by Ben Aston
    I'd like to program against interfaces when working with NHibernate due to type dependency issues within the solution I am working with. SO questions such as this indicate it is possible. I have an ILocation interface and a concrete Location type. Will the following work? HBM mapping: <class name="ILocation" abstract="true" table="ILocation"> <id name="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000"> <column name="LocationId" /> <generator class="guid" /> </id> <union-subclass table="Location" name="Location"> <property name="Name" type="System.String"/> </union-subclass> </class> Detached criteria usage using the interface: var criteria = DetachedCriteria.For<ILocation>().Add(Restrictions.Eq("Name", "blah")); var locations = criteria.GetExecutableCriteria(UoW.Session).List<ILocation>(); Are there any issues with not using the hilo ID generator and/or with this approach in general?

    Read the article

  • transactions and delete using fluent nhibernate

    - by Will I Am
    I am starting to play with (Fluent) nHibernate and I am wondering if someone can help with the following. I'm sure it's a total noob question. I want to do: delete from TABX where name = 'abc' where table TABX is defined as: ID int name varchar(32) ... I build the code based on internet samples: using (ITransaction transaction = session.BeginTransaction()) { IQuery query = session.CreateQuery("FROM TABX WHERE name = :uid") .SetString("uid", "abc"); session.Delete(query.List<Person>()[0]); transaction.Commit(); } but alas, it's generating two queries (one select and one delete). I want to do this in a single statement, as in my original SQL. What is the correct way of doing this? Also, I noticed that in most samples on the internet, people tend to always wrap all queries in transactions. Why is that? If I'm only running a single statement, that seems an overkill. Do people tend to just mindlessly cut and paste, or is there a reason beyond that? For example, in my query above, if I do manage it to get it from two queries down to one, i should be able to remove the begin/commit transaction, no? if it matters, I'm using PostgreSQL for experimenting.

    Read the article

  • How to set connection string dynamically in NHibernate

    - by jcreddy
    Hi I want assign connection string for NHibernate using following code and getting exception (bold). log4net.Config.DOMConfigurator.Configure(); Configuration config = new Configuration(); IDictionary props = new Hashtable(); props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider"; props["hibernate.dialect"] = "NHibernate.Dialect.MsSql2000Dialect"; props["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlClientDriver"; props["hibernate.connection.connection_string"] = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample;Data Source=HYDHTC92318D\SQLEXPRESS"; props["hibernate.connection.current_session_context_class"] = "web"; props["hibernate.connection.show_sql"] = "true"; props["hibernate.connection.proxyfactoryfactory.factory_class"] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"; foreach (DictionaryEntry de in props) { config.SetProperty(de.Key.ToString(), de.Value.ToString()); } config.AddAssembly("nhibernator"); factory = config.BuildSessionFactory(); session = factory.OpenSession(); The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle Please let me know the solution. Regards JCReddy

    Read the article

  • NHibernate Criteria

    - by Vamsi
    public class A { public string aname {get; set;} public string aId {get; set;} public string bId {get; set;} } public class B { public string bId {get; set;} public string bname {get; set;} public string cId {get; set;} } public class C { public string cId {get; set;} public string cfirstname {get; set;} public string clastname {get; set;} } public class abcDTO { public string aname {get; set;} public string bname {get; set;} public string clastname {get; set;} } Evetually the query which I am looking is SELECT a.aid, b.bname, c.clastname FROM A thisa inner join B thisb on thisa.bid=thisb.bid inner join C thisc on thisb.cid=thisc.cid and this_.POLICY_SEARCH_NBR like '%-996654%' The criteria which I am trying is, Please let me know the best possible way to write a criteria so that I can get the abcdto object as result var policyInsuranceBusiness = DetachedCriteria.For() .SetProjection(Projections.Property("a.aid")) .Add(Restrictions.Like("a.aid", "1-SAP-3-996654", MatchMode.Anywhere)) .CreateCriteria("b.bid", "b", JoinType.InnerJoin) .SetProjection(Projections.Property("b.bname")) // ERROR OUT - COULD NOT RESOLVE PROPERTY .CreateCriteria("c.cid", "c", JoinType.InnerJoin) .SetProjection(Projections.Property("c.clastname")); // ERROR - COULD NOT RESOLVE PROPERTY IList plo = policyInsuranceBusiness.GetExecutableCriteria(_session).SetResultTransformer(NHibernate.Transform.Transformers .AliasToBean();

    Read the article

  • NHibernate mapping for subclasses and joined-subclasses

    - by Husain
    In a project that I am working on, I have the following entities: Analyst, Client and Contractor. Each inherit from a base class User. public abstract class User { public virtual int Id { get; set; } public virtual string Username { get; set; } public virtual string FullName { get; set; } } I then have the other classes inheriting from the base class as: public class Analyst : User { // Empty class. There are no additional properties for an analyst. } public class Client : User { // Empty class. There are no additional properties for a client. } public class Contractor : User { public int TotalJobs { get; set; } public int JobsInProgress { get; set; } } For the above classes, I have the following table structure: USER ---- UserId Username FullName UserType (1 = Analyst, 2 = Client, 3 = Contractor) CONTRACTOR ---------- UserId TotalJobs JobsInProgress There are no tables for Analyst and Client classes. I would like to know how I can write the NHibernate mapping file for the Contractor class. For the other classes, I have created a User mapping file and added Client and Analyst as sub-classes. How can I map the Contractor class?

    Read the article

  • Fluent NHibernate Repository with subclasses

    - by reallyJim
    Having some difficulty understanding the best way to implement subclasses with a generic repository using Fluent NHibernate. I have a base class and two subclasses, say: public abstract class Person { public virtual int PersonId { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } public class Student : Person { public virtual decimal GPA { get; set; } } public class Teacher : Person { public virtual decimal Salary { get; set; } } My Mappings are as follows: public class PersonMap : ClassMap { public PersonMap() { Table("Persons"); Id(x => x.PersonId).GeneratedBy.Identity(); Map(x => x.FirstName); Map(x => x.LastName); } } public class StudentMap : SubclassMap<Student> { public StudentMap() { Table("Students"); KeyColumn("PersonId"); Map(x => x.GPA); } } public class TeacherMap : SubclassMap<Teacher> { public TeacherMap() { Table("Teachers"); KeyColumn("PersonId"); Map(x => x.Salary); } } I use a generic repository to save/retreive/update the entities, and it works great--provided I'm working with Repository--where I already know that I'm working with students or working with teachers. The problem I run into is this: What happens when I have an ID, and need to determine the TYPE of person? If a user comes to my site as PersonId = 23, how do I go about figuring out which type of person it is?

    Read the article

  • How to Specify Columntype in fluent nHibernate?

    - by Bipul
    I have a class CaptionItem public class CaptionItem { public virtual int SystemId { get; set; } public virtual int Version { get; set; } protected internal virtual IDictionary<string, string> CaptionValues {get; private set;} } I am using following code for nHibernate mapping Id(x => x.SystemId); Version(x => x.Version); Cache.ReadWrite().IncludeAll(); HasMany(x => x.CaptionValues) .KeyColumn("CaptionItem_Id") .AsMap<string>(idx => idx.Column("CaptionSet_Name"), elem => elem.Column("Text")) .Not.LazyLoad() .Cascade.Delete() .Table("CaptionValue") .Cache.ReadWrite().IncludeAll(); So in database two tables get created. One CaptionValue and other CaptionItem. In CaptionItem table has three columns 1. CaptionItem_Id int 2. Text nvarchar(255) 3. CaptionSet_Name nvarchar(255) Now, my question is how can I make the columnt type of Text to nvarchar(max)? Thanks in advance.

    Read the article

  • FluentNHibernate mapping of composite foreign keys

    - by Faron
    I have an existing database schema and wish to replace the custom data access code with Fluent.NHibernate. The database schema cannot be changed since it already exists in a shipping product. And it is preferable if the domain objects did not change or only changed minimally. I am having trouble mapping one unusual schema construct illustrated with the following table structure: CREATE TABLE [Container] ( [ContainerId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_Container] PRIMARY KEY ( [ContainerId] ASC ) ) CREATE TABLE [Item] ( [ItemId] [uniqueidentifier] NOT NULL, [ContainerId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_Item] PRIMARY KEY ( [ContainerId] ASC, [ItemId] ASC ) ) CREATE TABLE [Property] ( [ContainerId] [uniqueidentifier] NOT NULL, [PropertyId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_Property] PRIMARY KEY ( [ContainerId] ASC, [PropertyId] ASC ) ) CREATE TABLE [Item_Property] ( [ContainerId] [uniqueidentifier] NOT NULL, [ItemId] [uniqueidentifier] NOT NULL, [PropertyId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_Item_Property] PRIMARY KEY ( [ContainerId] ASC, [ItemId] ASC, [PropertyId] ASC ) ) CREATE TABLE [Container_Property] ( [ContainerId] [uniqueidentifier] NOT NULL, [PropertyId] [uniqueidentifier] NOT NULL, CONSTRAINT [PK_Container_Property] PRIMARY KEY ( [ContainerId] ASC, [PropertyId] ASC ) ) The existing domain model has the following class structure: The Property class contains other members representing the property's name and value. The ContainerProperty and ItemProperty classes have no additional members. They exist only to identify the owner of the Property. The Container and Item classes have methods that return collections of ContainerProperty and ItemProperty respectively. Additionally, the Container class has a method that returns a collection of all of the Property objects in the object graph. My best guess is that this was either a convenience method or a legacy method that was never removed. The business logic mainly works with Item (as the aggregate root) and only works with a Container when adding or removing Items. I have tried several techniques for mapping this but none work so I won't include them here unless someone asks for them. How would you map this?

    Read the article

  • NHibernate One to One Foreign Key ON DELETE CASCADE

    - by xll
    I need to implement One-to-one association between Project and ProjecSettings using fluent NHibernate: public class ProjectMap : ClassMap<Project> { public ProjectMap() { Id(x => x.Id) .UniqueKey(MapUtils.Col<Project>(x => x.Id)) .GeneratedBy.HiLo("NHHiLoIdentity", "NextHiValue", "1000", string.Format("[EntityName] = '[{0}]'", MapUtils.Table<Project>())) .Not.Nullable(); HasOne(x => x.ProjectSettings) .PropertyRef(x => x.Project); } } public class ProjectSettingsMap : ClassMap<ProjectSettings> { public ProjectSettingsMap() { Id(x => x.Id) .UniqueKey(MapUtils.Col<ProjectSettings>(x => x.Id)) .GeneratedBy.HiLo("NHHiLoIdentity", "NextHiValue", "1000", string.Format("[EntityName] = '[{0}]'", MapUtils.Table<ProjectSettings>())); References(x => x.Project) .Column(MapUtils.Ref<ProjectSettings, Project>(p => p.Project, p => p.Id)) .Unique() .Not.Nullable(); } } This results in the following sql for Project Settings: CREATE TABLE ProjectSettings ( Id bigint PRIMARY KEY NOT NULL, Project_Project_Id bigint NOT NULL UNIQUE, /* Foreign keys */ FOREIGN KEY (Project_Project_Id) REFERENCES Project() ON DELETE NO ACTION ON UPDATE NO ACTION ); What I am trying to achieve is to have ON DELETE CASCADE for the FOREIGN KEY (Project_Project_Id), so that when the project is deleted through sql query, it's settings are deleted too. How can I achieve this ? EDIT: I know about Cascade.Delete() option, but it's not what I need. Is there any way to intercept the FK statement generation?

    Read the article

  • NHibernate mapping with two special cases

    - by brainimus
    I am using NHibernate to map a class to a database table. The Part table has an ID column (primary key) and a ParentPart column (along with a few others). class Part { public virtual long ID{ get; set; } public virtual Part ParentPart { get; set; } } The ParentPart is normally another valid part in the part table but I have two special cases. I have a case where the ParentPart column can be 0 (zero) and another case where it can be -1. Neither of these cases currently represent another valid Part object. I was thinking I could make 2 subclasses of Part (ZeroPart and NegativeOnePart) that would never persist. I want the zero and -1 values to be entered in the column but not persist the entire ZeroPart or NegativeOnePart objects. I am unsure how to map this (I'm using hbm files) or if this even the correct approach. How can I map this so that normal valid parts are persisted but I can also handle the special cases? As an aside: My current hbm file has the Part.ID's unsaved value as zero but I think I can just change this in the mapping to something different and default it in the class.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >