Search Results

Search found 1981 results on 80 pages for 'fluent nhibernate'.

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

  • Make Fluent NHibernate output schema update to file

    - by Bender
    I am successfully getting Fluent NHibernate to update my database by calling UpdateBaseFiles: Public Sub UpdateBaseFiles() Dim db As SQLiteConfiguration db = SQLiteConfiguration.Standard.UsingFile(BASE_DBNAME) Fluently.Configure() _ .Database(db) _ .Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of FluentMap)()) _ .ExposeConfiguration(AddressOf UpdateSchema) _ .BuildConfiguration() End Sub Private Sub UpdateSchema(ByVal Config As Configuration) Dim SchemaUpdater As New SchemaUpdate(Config) SchemaUpdater.Execute(True, True) End Sub How do I output the DDL to a file, I do this when initially creating the schema by using: Private Sub BuildSchema(ByVal Config As Configuration) Dim SchemaExporter As New SchemaExport(Config) SchemaExporter.SetOutputFile("schema.sql") SchemaExporter.Create(False, True) End Sub but SchemaUpdate does not have a SetOutputFile method.

    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

  • Mapping interface or abstract class component

    - by Yann Trevin
    Please consider the following simple use case: public class Foo { public virtual int Id { get; protected set; } public virtual IBar Bar { get; set; } } public interface IBar { string Text { get; set; } } public class Bar : IBar { public virtual string Text { get; set; } } And the fluent-nhibernate map class: public class FooMap : ClassMap<Foo> { public FooMap() { Id(x => x.Id); Component(x => x.Bar, m => { m.Map(x => x.Text); }); } } While running any query with configuration, I get the following exception: NHibernate.InstantiationException: "Cannot instantiate abstract class or interface: NHMappingTest.IBar" It seems that NHibernate tries to instantiate an IBar object instead of the Bar concrete class. How to let Fluent-NHibernate know which concrete class to instantiate when the property returns an interface or an abstract base class? EDIT: Explicitly specify the type of component by writing Component<Bar> (as suggested by Sly) has no effect and causes the same exception to occur. EDIT2: Thanks to vedklyv and Paul Batum: such a mapping should be soon is now possible.

    Read the article

  • Commit is VERY slow in my NHibernate / SQLite project

    - by Tom Bushell
    I've just started doing some real-world performance testing on my Fluent NHibernate / SQLite project, and am experiencing some serious delays when when I Commit to the database. By serious, I mean taking 20 - 30 seconds to Commit 30 K of data! This delay seems to get worse as the database grows. When the SQLite DB file is empty, commits happen almost instantly, but when it grows to 10 Meg, I see these huge delays. The database has 16 tables, averaging 10 columns each. One possible problem is that I'm storing a dozen or so IList members, but they are typically only 200 elements long. But this is a recent addition to Fluent NHibernate automapping, which stores each float in a single table row, so maybe that's a potential problem. Any suggestions on how to track this down? I suspect SQLite is the culprit, but maybe it's NHibernate? I don't have any experience with profilers, but am thinking of getting one. I'm aware of NHibernate Profiler - any recommendations for profilers that work well with SQLite? Here's the method that saves the data - it's just a SaveOrUpdate call and a Commit, if you ignore all the error handling and debug logging. public static void SaveMeasurement(object measurement) { Debug.WriteLine("\r\n---SaveMeasurement---"); // Get the application's database session var session = GetSession(); using (var transaction = session.BeginTransaction()) { try { session.SaveOrUpdate(measurement); } catch (Exception e) { throw new ApplicationException( "\r\n SaveMeasurement->SaveOrUpdate failed\r\n\r\n", e); } try { Debug.WriteLine("\r\n---Commit---"); transaction.Commit(); Debug.WriteLine("\r\n---Commit Complete---"); } catch (Exception e) { throw new ApplicationException( "\r\n SaveMeasurement->Commit failed\r\n\r\n", e); } } }

    Read the article

  • One-to-one Mapping issue with NHibernate/Fluent: Foreign Key not updateing

    - by Trevor
    Summary: Parent and Child class. One to one relationship between the Parent and Child. Parent has a FK property which references the primary key of the Child. Code as follows: public class NHTestParent { public virtual Guid NHTestParentId { get; set; } public virtual Guid ChildId { get { return ChildRef.NHTestChildId; } set { } } public virtual string ParentName { get; set; } protected NHTestChild _childRef; public virtual NHTestChild ChildRef { get { if (_childRef == null) _childRef = new NHTestChild(); return _childRef; } set { _childRef = value; } } } public class NHTestChild { public virtual Guid NHTestChildId { get; set; } public virtual string ChildName { get; set; } } With the following Fluent mappings: Parent Mapping Id(x => x.NHTestParentId); Map(x => x.ParentName); Map(x => x.ChildId); References(x => x.ChildRef, "ChildId").Cascade.All(); Child Mapping: Id(x => x.NHTestChildId); Map(x => x.ChildName); If I do something like (pseudo code) ... HTestParent parent = new NHTestParent(); parent.ParentName = "Parent 1"; parent.ChildRef.ChildName = "Child 1"; nhibernateSession.SaveOrUpdate(aParent); Commit; ... I get an error: "Invalid index 3 for this SqlParameterCollection with Count=3" If I change the parent 'References' line as follows (i.e. provide the name of the child property I'm pointing at): References(x => x.ChildRef, "ChildId").PropertyRef("NHTestChildId").Cascade.All(); I get the error: "Unable to resolve property: NHTestChildId" So, I tried the 'HasOne()' reference setting, as follows: HasOne<NHTestChild>(x => x.ChildRef).ForeignKey("ChildId").Cascade.All().Fetch.Join(); This results in the save working, but the load fails to find the child. If I inspect the SQL Nhibernate produces I can see that NHibernate is assuming the Primary key of the parent is the link to the child (i.e. load join condition is "parent.NHTestParentId = child.NHTestChildId). The 'ForeignKey' specified appears to be ignored. I can set any value and no error occurs - the join just always fails and no child is returned. I've tried a number of slight variations on the above. It seems like it should be a simple thing to achieve. Any ideas?

    Read the article

  • nhibernate fluent bool to smallint mapping

    - by Raul
    In my application I have a bool property named DisplayIndicator. In the database (DB2) it's correspondence is DISPL_IND column of type smallint. The correspondence is the following: [DisplayINdicator=True, DISPL_IND=1] and [DisplayINdicator=False, DISPL_IND=0] Is it possible to map using nhibernate fluence the bool property to smallint?

    Read the article

  • Fluent NHibermate and Polymorphism and a Newbie!

    - by Andy Baker
    I'm a fluent nhibernate newbie and I'm struggling mapping a hierarchy of polymorhophic objects. I've produced the following Model that recreates the essence of what I'm doing in my real application. I have a ProductList and several specialised type of products; public class MyProductList { public virtual int Id { get; set; } public virtual string Name {get;set;} public virtual IList<Product> Products { get; set; } public MyProductList() { Products = new List<Product>(); } } public class Product { public virtual int Id { get; set; } public virtual string ProductDescription {get;set;} } public class SizedProduct : Product { public virtual decimal Size {get;set;} } public class BundleProduct : Product { public virtual Product BundleItem1 {get;set;} public virtual Product BundleItem2 {get;set;} } Note that I have a specialised type of Product called BundleProduct that has two products attached. I can add any of the specialised types of product to MyProductList and a bundle Product can be made up of any of the specialised types of product too. Here is the fluent nhibernate mapping that I'm using; public class MyListMap : ClassMap<MyList> { public MyListMap() { Id(ml => ml.Id); Map(ml => ml.Name); HasManyToMany(ml => ml.Products).Cascade.All(); } } public class ProductMap : ClassMap<Product> { public ProductMap() { Id(prod => prod.Id); Map(prod => prod.ProductDescription); } } public class SizedProductMap : SubclassMap<SizedProduct> { public SizedProductMap() { Map(sp => sp.Size); } } public class BundleProductMap : SubclassMap<BundleProduct> { public BundleProductMap() { References(bp => bp.BundleItem1).Cascade.All(); References(bp => bp.BundleItem2).Cascade.All(); } } I haven't configured have any reverse mappings, so a product doesn't know which Lists it belongs to or which bundles it is part of. Next I add some products to my list; MyList ml = new MyList() { Name = "Example" }; ml.Products.Add(new Product() { ProductDescription = "PSU" }); ml.Products.Add(new SizedProduct() { ProductDescription = "Extension Cable", Size = 2.0M }); ml.Products.Add(new BundleProduct() { ProductDescription = "Fan & Cable", BundleItem1 = new Product() { ProductDescription = "Fan Power Cable" }, BundleItem2 = new SizedProduct() { ProductDescription = "80mm Fan", Size = 80M } }); When I persist my list to the database and reload it, the list itself contains the items I expect ie MyList[0] has a type of Product, MyList[1] has a type of SizedProduct, and MyList[2] has a type of BundleProduct - great! If I navigate to the BundleProduct, I'm not able to see the types of Product attached to the BundleItem1 or BundleItem2 instead they are always proxies to the Product - in this example BundleItem2 should be a SizedProduct. Is there anything I can do to resove this either in my model or the mapping? Thanks in advance for your help.

    Read the article

  • NHibernate and SetSessionAuth audit columns

    - by user86431
    We have audit columns set by triggers. For obscure security reasons predating my tenure and out of my control, we log in with a generic user, and do a 'set session authorization' to change the user to the db user of the user who is logged in. When we converted to NHibernate, it creates a whole new session and jacks everything up when we try to do a set session auth, so we turned the set session auth off... Now we are trying to find out a way to get NHibernate to let us do 'set session authorization' without recycling the session on us, so we can use our existing trigger based audit column stuff with both legacy apps, and our new NHibernate apps. It's not a ideal soloution, or the best way to do it even, but is it possible? I was hoping there was a alternate interface that allowed this kind of access. Does anyone know how to do it, or can you point me towards and good hints? Thanks, Eric-

    Read the article

  • How to have NHibernate persist a String.Empty property value as NULL

    - by Todd
    I have a fairly simple class that I want to save to SQL Server via NHibernate (w/ Fluent mappings). The class is made up mostly of optional string fields. My problem is I default the class fields to string.empty to avoid NullRefExceptions and when NHibernate saves the row to the database each column contains an empty string instead of null. Question: Is there a way for me to get NHibernate to automatically save null when the string property is an empty string? Or do I need to litter my code with if (string.empty) checks?

    Read the article

  • Mapping table and a simple view with Fluent NHibernate

    - by adrin
    I have mapped a simple entity, let's say an invoice using Fluent NHibernate, everything works fine... after a while it turns out that very frequently i need to process 'sent invoices' (by sent invoices we mean all entities that fulfill invoice.sent==true condition)... is there a way to easily abstract 'sent invoices' in terms of my data access layer? I dont like the idea of having aforementioned condition repeated in half of my repository methods. I thought that using a simple filtering view would be optimal, but how could it be done? Maybe I am doing it terribly wrong and someone would help me realize it :)?

    Read the article

  • fluent nhibernate m-to-m with column

    - by csetzkorn
    Hi, I am used to hbm files and started using fluent nhibernate recently. Creating an m-to-m relationship between two entities A and B is quite simple In A I create: public virtual IList Bs { get; set; } and then I use: mapping.HasManyToMany(x = x.Bs); That’s it and I can do: A a = new A(); a.Bs.Add(b); My problem is that I would like to have an additional column in my dedicated m-to-m database table which holds the two foreign keys. What is the simplest way to achieve this in FNH? Would I have to create a dedicated entity for the m-to-m realtionship or is there a simpler solution? Thanks. Best wishes, Christian

    Read the article

  • Fluent many-to-many: Deleting one end does not remove the entry in the relation table

    - by Kristoffer
    I have two classes (Parent, Child) that have a many-to-many relationship that only one end (Parent) knows about. My problem is that when I delete a "relation unaware" object (Child), the record in the many-to-many table is left. I want the relationship to be removed regardless of which end of it is deleted. How can I do that with Fluent NHibernate mappings, without adding a Parent property on Child? The classes: public class Parent { public Guid Id { get; set; } public IList<Child> Children { get; set; } } public class Child { public Guid Id { get; set; } // Don't want the property below: // public Parent Parent { get; set; } }

    Read the article

  • How to debug Fluent nHibernate

    - by Matt Thrower
    Hi, I'm having some trouble with Fluent nHibernate. I added a column to a table and I thought I'd correctly changed the mappings and the connected data objects to correctly reflect this. However when I tried to run my application again I kept getting this error: System.Data.SqlClient.SqlException: Invalid column name 'Workflow_id'. I really couldn't see what the problem was with the changes I'd made so I reverted back to the original versions of the mapping and data object files from source control and removed the offending column from the database. But I'm still getting the same error. I'd like some advice on how to debug this. The SQL that gets reported on the error is semi-nonsensical: SELECT regions0_.Page_id as Page5_1_, regions0_.Id as Id1_, regions0_.Id as Id27_0_, regions0_.RegionId as RegionId27_0_, regions0_.RegionTemplate_id as RegionTe3_27_0_, regions0_.Workflow_id as Workflow4_27_0_ FROM [Region] regions0_ WHERE regions0_.Page_id=? And it won't execute as valid SQL anyway. Any ideas as to where to go from here?

    Read the article

  • mapping 'value object' collection in (Fluent) NHibernate

    - by adrin
    I have the following entity public class Employee { public virtual int Id {get;set;} public virtual ISet<Hour> XboxBreakHours{get;set} public virtual ISet<Hour> CoffeeBreakHours {get;set} } public class Hour { public DateTime Time {get;set;} } (What I want to do here is store information that employee A plays Xbox everyday let's say at 9:00 13:30 and has a coffee break everyday at 7:00 12:30 18:00) - I am not sure if my approach is valid at all here. The question is how should my (ideally fluent) mappings look like here? It is not necessary (from my point of view) for Hour class to have Id or be accessible from some kind of repository.

    Read the article

  • (Fluent)NHibernate: Mapping an IDictionary<MappedClass, MyEnum>

    - by anthony
    I've found a number of posts about this but none seem to help me directly. Also there seems to be confusion about solutions working or not working during different stages of FluentNHibernate's development. I have the following classes: public class MappedClass { ... } public enum MyEnum { One, Two } public class Foo { ... public virtual IDictionary<MappedClass, MyEnum> Values { get; set; } } My questions are: Will I need a separate (third) table of MyEnum? How can I map the MyEnum type? Should I? What should Foo's mapping look like? I've tried mapping HasMany(x = x.Values).AsMap("MappedClass")... This results in: NHibernate.MappingException : Association references unmapped class: MyEnum

    Read the article

  • Fluent mapping help

    - by Matt Thrower
    Hi, This is probably a very simple question but I'm new to nHibernate and I'm having trouble working this out. I have a Page object, which can have many Region objects. I also have a Workflow object. Page and Region objects both have a relationship to Workflow and it's this double association that I'm having trouble with. The PageMap has HasMany(Function(x) x.Regions).Cascade.All() And the RegionMap has: References(Function(x) x.Page) And this all seems to work. But how do I define the relationship between Workflow and these two objects?

    Read the article

  • NHibernate Mapping and Querying Where Tables are Related But No Foreign Key Constraint

    - by IanT8
    I'm fairly new to NHibernate, and I need to ask a couple of questions relating to a very frequent scenario. The following simplified example illustrates the problem. I have two tables named Equipment and Users. Users is a set of system administrators. Equipment is a set of machinery. Tables: Users table has UserId int and LoginName nvarchar(64). Equipment table has EquipId int, EquipType nvarchar(64), UpdatedBy int. Behavior: System administrators can make changes to Equipment, and when they do, the UpdatedBy field of Equipment is "normally" set to their User Id. Users can be deleted at any time. New Equipment items have an UpdatedBy value of null. There's no foreign key constraint on Equipment.UpdatedBy which means: Equipment.UpdatedBy can be null. Equipment.UpdatedBy value can be = existing User.UserId value Equipment.UpdatedBy value can be = non-existent User.UserId value To find Equipment and who last updated the Equipment, I might query like this: select E.EquipId, E.EquipName, U.UserId, U.LoginName from Equipment E left outer join Users U on. E.UpdatedBy = U.UserId Simple enough. So how to do that in NHibernate? My mappings might be as follows: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Data" assembly="Data"> <class name="User" table="Users"> <id name="Id" column="UserId" unsaved-value="0"> <generator class="native" /> </id> <property name="LoginName" unique="true" not-null="true" /> </class> <class name="Equipment" table="Equipment"> <id name="Id" column="EquipId" type="int" unsaved-value="0"> <generator class="native" /> </id> <property name="EquipType" /> <many-to-one name="UpdatedBy" class="User" column="UpdatedBy" /> </class> </hibernate-mapping> So how do I get all items of equipment and who updated them? using (ISession session = sessionManager.OpenSession()) { List<Data.Equipment> equipList = session .CreateCriteria<Data.Equipment>() // Do I need to SetFetchmode or specify that I // want to join onto User here? If so how? .List<Data.Equipment>(); foreach (Data.Equipment item in equipList) { Debug.WriteLine("\nEquip Id: " + item.Id); Debug.WriteLine("Equip Type: " + item.EquipType); if (item.UpdatedBy.Country != null) Debug.WriteLine("Updated By: " + item.UpdatedBy.LoginName); else Debug.WriteLine("Updated by: Nobody"); } } When Equipment.UpdatedBy = 3 and there is no Users.UserId = 3, the above fail I also have a feeling that the generated SQL is a select all from Equipment followed by many select columns from Users where UserId = n whereas I'd expected NHibernate to left join as per my plain ordinary SQL and do one hit. If I can tell NHibernate to do the query in one hit, how do I do that? Time is of the essence on my project, so any help you could provide is gratefully received. If you're speculating about how NHibernate might work in this scenario, please say you're not absolutely sure. Many thanks.

    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

  • Fluent NHibernate IDictionary with composite element mapping

    - by Alessandro Di Lello
    Hi there, i have these 2 classes: public class Category { IDictionary<string, CategoryResorce> _resources; } public class CategoryResource { public virtual string Name { get; set; } public virtual string Description { get; set; } } and this is xml mapping <class name="Category" table="Categories"> <id name="ID"> <generator class="identity"/> </id> <map name="Resources" table="CategoriesResources" lazy="false"> <key column="EntityID" /> <index column="LangCode" type="string"/> <composite-element class="Aca3.Models.Resources.CategoryResource"> <property name="Name" column="Name" /> <property name="Description" column="Description"/> </composite-element> </map> </class> and i'd like to write it with Fluent. I found something similar and i was trying with this code: HasMany(x => x.Resources) .AsMap<string>("LangCode") .AsIndexedCollection<string>("LangCode", c => c.GetIndexMapping()) .Cascade.All() .KeyColumn("EntityID"); but i dont know how to map the CategoryResource entity as a composite element inside the Category element. Any advice ? thanks

    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

  • how is FLUENT api different from other API

    - by intern
    i have come across fluent api while studying DSLs. i have searched alot on FLUENT API..the basic conclusion which i could draw out was that fluent api uses method chaining in order to make the code fluent. but i cannot understand that in object oriented languages we can always create an object and can call the methods related to it. then how is FLUENT api different from it? what other features does fluent api add?

    Read the article

  • Unique Constraint Nhibernate.

    - by Will
    I have a object with a Nhibernate mapping that has a surrogate ID and a natual ID. Since of cource the natural ID is uniquely constrained a insert query will fail if the object is already in the database with the same natural ID. My solution for this has been to manually check to see if natural IDs are in the database before trying to insert. Is there a way to specify Nhibernate to do a select before insert on natural Id's/Unique Constraints?

    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

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