I have a Store that contains a list of Products:
var store = new Store();
store.Products.Add(new Product{ Id = 1, Name = "Apples" };
store.Products.Add(new Product{ Id = 2, Name = "Oranges" };
Database.Save(store);
Now, I want to edit one of the Products, but with a transient entity. This will be, for example, data from a web browser...
I have a versioned entity, and this is what happens when I use SaveOrUpdate() vs. SaveOrUpdateCopy():
// create new entity
var entity = new Entity{ Id = Guid.Empty });
Console.WriteLine(entity.Version); // prints out 0
// save the new entity
GetNewSession();
entity.SaveOrUpdate();
Console.WriteLine(entity.Version); // prints out 1
Get...
My client likes programs like Microsoft OneNote where changes are saved automatically, and he can choose to discard when he explicitly wants to do so. I will have to implement some undo functionality, but I'll figure that out some other time.
With NHibernate, I suppose I can call ISession.Update on every single property / binding change...
Hey,
I'm mapping a very simple Users table, and i have a column named 'LastLoginDate' which is defined as nullable in sql server.
My mapping looks like this :
public Users {
Id(x => x.UserId);
Map(x => x.UserName);
...
...
Map(x => x.LastLoginDate).Nullable();
}
But everytime I try to save this entity programatic...
Hi, Which version of MySql.data.dll should I use with NHibernate 2.1.2.4000?? This is also with the latest version of Fluent NH.
Thank you
...
I'm developing an application which will have these classes:
class Shortcut
{
public string Name { get; }
public IList<Trigger> Triggers { get; }
public IList<Action> Actions { get; }
}
class Trigger
{
public string Name { get; }
}
class Action
{
public string Name { get; }
}
And I will have 20+ more classes, whi...
A user can have many addresses, but I want to retrieve the latest entry for the user.
In sql I would do:
SELECT TOP 1 *
FROM UserAddress
WHERE userID = @userID
How can I create a criteria query with the same logic?
Is there a TOP functionality?
...
I have an enumeration of type int in my entity, UserStatus.
I want to get all users where the UserStatus <> Cancelled.
So:
Session.CreateCriteria(typeof(User))
.Add(Expression.Eq("UserStatus", (int)UserStatus.Cancelled)
.UniqueResult<User>();
The above is fore equal, I need to get not equal.
...
We are using NHibernate in a rich client application. It is a pretty open application (the user searches for a dataset or creates a new one, changes the data and saves the data set.
We leave the session open, because sometimes we have to lazy load some properties of the object (nested object structure).
This means one big problem
if w...
Okay, so yesterday I managed to get the latest trunk builds of NHibernate and FluentNHibernate to work with my latest little project. (I'm working on a bug tracking application.) I created a nice data access layer using the Repository pattern.
I decided that my entities are nothing special, and also that with the current maturity of ORM...
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...
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 col...
What would be the best way to achieve a human readable number,
currently have Identity set to a surrogate key.
have been thinking of identity seed but this would lead to gaps.
If i were to generate within a transaction scope then, would concurrency have an effect ?
Would prefer to avoid DBCC CHECKIDENT trigger.
thanks.
...
Hello guys. I'm having some problems with NHibernate when it comes to mapping many to many relationships, specially this one.
I have a Category table, which each parent can have as many childs as it needs, and it can be also a parent.
When i try to select something from category table, i get an error:
ERROR: 42601: syntax error at or ...
If I have a field in the db which stores a set of comma separated strings (says tags), how can I instruct fluent Nhibernate to pick it up at List<string>()
e.g.
Public IList<string> Tags {get; set;}
Db field values:
Mvc, .net, FNH
...
I am using NHibernate in an MVC 2.0 application. Essentially I want to keep track of the number of times each product shows up in a search result. For example, when somebody searches for a widget the product named WidgetA will show up in the first page of the search results. At this point i will increment a field in the database to refl...
I have a rather large inheritance hierarchy in which some of the subclasses add very little and others add quite a bit. I don't want to map the entire hierarchy using either "table per class hierarchy" or "table per subclass" due to the size and complexity of the hierarchy. Ideally I'd like to mix mapping strategies such that portions ...
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...
I spent the rest of the evening reading StackOverflow questions and also some blog entries and links about the subject. All of them turned out to be very helpful, but I still feel that they don't really answer my question.
So, I'm developing a simple web application. I'd like to create a reusable data access layer which I can later reus...
Can Castle ActiveRecord do optimistic locking on properties? I found optimistic locking for the entire class, but not for an individual property. In my case, I need to make it so that adding/removing elements in a collection does not update the version number of the entity (so for example, adding a Product to a Store without changing any...