I am having hard times convincing NHibernate (EF was able to do it) to filter based on the Hour property of a DateTime entity property. My entity goes something like :
public class Invoice {
// ...
public DateTime Time { get; set; }
// ...
}
I need to retrieve all the invoices that were "made" at a certain hour (let's say ...
Here is roughly our data model (the entity names are fake and only for example purposes).
Product has a many-to-many relationship with Shipper. Shipper then has a one-to-many relationship with Warehouse.
Basically: Product has many Shippers which have many Warehouses.
We have a mapping from Product to Shipper and from Warehouse to Shi...
Hi, could somebody please review my source and let me know where I am going wrong. I am trying to insert a new application record and am receiving an exception when I try session.Flush().
Here is the application mapping (have changed some values for display purposes):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="......
Hello,
I am going to try using NHibernate, the reason I stayed away from NHibernate so far was the xml-mapping part. Now that (I found out) there is fluent nhibernate, looks like we don't need to do xml mapping.
But I am wondering if starting with some xml mapping, would be more helpful in learning and getting comfortable with NHibernat...
I have problem with model binding in my ASP.NET MVC 2 RC application that uses NHibernate for data access. We are trying to build the application in a Ruby on Rails way and have a very simple architecture where the domain entities are used all the way from the database to the view.
The application has a couple of domain entities which c...
I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach with database access handled by NHibernate. I have domain model class (Administrator) that I want to inject a dependency into via an IOC Container such as Castle Windsor, something like this:
public class Administrator
{
public virtual int Id { g...
I have a method that queries the database (in this case a view) for parent records, gets and updates a child of each parent record, saves the child record, and then queries for the parent records. There is a one-to-one relationship between the child and parent but the relationship is not defined in the mapping files. I can see that the...
I'm just starting out with Linq to NHibernate and having troubles with a pretty simple query. I have a database column that is defined as a varchar. In the linq query I need to compare that value to a datetime value (all of the values stored in the varchar column are valid dates). I'm trying this:
var list = (from o in session.Linq<O...
I have a table GL that contains GLCode. I need to get a list of unique GLCodes, but get all the other columns. The following SQL produces the results I want.
select * from GL where GLId in (select Min(GLId) from GL group by GLCode )
Is there a way to do this using the Criteria API?
This is my best attempt:
var subQuery = Det...
I am encountering a very strange issue I wonder if anyone has seen before. I have as part of my Save() method in a repository that it will search out and find each associated tag by it's name. There is a line in there that looks like this.
var tagRepo = (from t in tagRepository.Query() where t.Name == tag.Name select t).SingleOrDefault(...
Hi, I need help in creating the correct fluent nh mapping for this kind of scenario:
A category can be a child of one or more categories. Thus, resulting to this entity:
public class Category : Entity, IAggregateRoot
{
[EntitySignature]
public virtual string Name { get; set; }
public virtual IList<Category> Parents { get; s...
Am using the following query to get a Client. The Client has a public Id of type long.
var client = Session.CreateQuery("from Client as c where c.Id = :Id").SetParameter("Id", 1, NHibernateUtil.Int64).UniqueResult<Client>();
Am getting the error:
NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.I...
Hi,
short version: is there a HQL equivalent for session.CreateCriteria(string)?
Long version:
The mapping looks like this:
<class name="MyClass" entity-name="MyClass">
...
</class>
<class name="MyClass" entity-name="SomeEntityName">
...
</class>
When I use session.CreateCriteria("SomeEntityName"), only objects stored...
Hi everybody,
I'm an NHibernate and fluent-nhibernate newbie. And I've got some problem with unique constraint and nhibernate mapping.
I've got the following part of domain model.
public class Batch
{
public virtual int Id {get; set;}
public virtual string Name {get; set;}
public virtual IList<BatchParameter> BatchParamete...
Hi all,
I wonder if there is a smooth way of keeping track of changed entities using NHibernate.
Session.IsDirty() is a fine way of knowing there are changes, but not which. Up to now, I've logged my changes in a List to be able to specify them later on. Eventually I would loop over that list and call Session.Save() on each of them an...
Hi,
My objects of type Object1 contain List Children1 property.
I would love to get these objects without children.
Seems like detachedCriteria.SetFetchMode ("Children1", FetchMode.Lazy) should be the thing,
but apparently it's not :(
I tried getting the data in using (new SessionScope()) and setting null to .Children1 but it didn't suc...
Client has a Report, Configuration etc properties. A client can have only one of each. Also, each report can belong to only one Client. This is in a way a one-to-one relationship. Therefore my Report table has a foreignkey column clientID. Same for the Configuration and other tables.
Now as per the definition of one-to-one that i read ...
When creating a mapping, I am reading that your collection property should look like:
public virtual ReadOnlyCollection<Product> Products
{
get { return new ReadOnlyCollection<Product>(new List<Product>(_products).AsReadOnly()); }
}
Why does it have to be like this? it seems to be returning a new collection everytime ...
Are there any internet resources that have a definitive guide to all of the cascade settings for NHibernate that will include examples of the class structure, HBM and the implications of actions with each of the cascade settings for all of the relationships with NH.
Also it would be helpful if there were examples for common associations...
I started switching some pre-existing nHibernate code in a Sharepoint-based ASP.NET project from eager loading and a new session every database hit, to lazy loading and a session for the duration of the HTTP request, and started running into a problem.
When we create an Item in this system, there are some many-to-one relationships that ...