Best way to update an table relationship reference in nhibernate? - nhibernate

Say I have this.
A country has many products and a product can have many countries (many to many).
Now product A has
US
Canada
Now for some reason they stop selling product A in Canada. How do I update product A to remove the relationship as now product A is no longer in Canada.
Should I clear the list called like ProudctA.Countries.Clear(). Then go and add the countries still selected back in?
ProductA.Countries.Add(loadCountry(id)) // this would be a loop and I would be loading the ids from the select countries.
Or should I some how figure out what has changed and called like a delete or something?
I am getting a list of Guid back from the server. The user just sees a select list box and choose the countries.
When they edit the Product both US and Canada were selected but then they choose to unselect Canada so only the US Guid was sent back to the server as selected.

i would do something like this
countriesToRemove = productA.Countries.Where(c => !selectedIds.Contains(c.Id)).ToList();
foreach(var country in countriesToRemove)
{
productA.Countries.Remove(country);
}
however since you already loaded them (are in session cache) and the link table entries are removed and inserted anyway it would only matter if nothing is removed.

Related

Adding new product with category tree - specific price problems

I installed an add-on for bulk action (called ba_importer v 1.1.24), I upload an Excel file with my data and create a group of products.
I can set the categories' tree or manually add ID of main categories and associated. I tried with no luck to use the tree features (like Home/Products/etc) and so I use all the ID of main category and all the associated. The result is a product with the correct categories set, but with no specific price from the customer group linked to a category.
I tried to edit a single product, remove all categories and set it one by one (set one, save, set one, save etc.) and then the specific price from the group linked to a category appears to the product.
Is there a better solution? I'm thinking about make a personal PHP page that reads an Excel file and sets all the information about the product, but I'm scared to face the same problem with the specific price. 
There is no such thing as "category-related specific price",
if you have specific prices tied to customer groups , these are created as a result of the add/update product action with ps_specific_price DB entries having id_group with your restricted ID.
It is likely that the bulk module acts directly with DB queries to speed up things and bypasses this operation, I've seen this behaviour with those kind of modules in the past.
Since you are talking of a paid add-on, I would definitely seek help from the developer.

Lookup Column Issue - List View Threshold exceeded

We use Sharepoint Foundation 2010 and we have 2 Lists in a site. Those are:
Customers List.
Sale Invoices List.
Customers List has Title field as Unique & Indexed Column.
Sale Invoices List has a lookup column (i.e., Customer) from the Customers List (Title).
My issue is:
Customers List has just crossed 5000 items. When I try to add a List Item in Sale Invoices List (where I have Lookup Column from Customers List), it throws an error as given below:
Error Message:- This is a lookup column that displays data from another list that currently exceeds the List View Threshold defined by the administrator (5000). To add items to the current list, please ask the list owner to remove this column.
I have increased temporarily the List View Threshold Limit to 6000 Items. It’s working fine now.
Is there any solution to fix the issue without increasing the List Items Threshold Limit?
Thanks in Advance.
You should look into archiving list items. Another thing you can think about doing is creating different lists for different time periods so that you can avoid this List View Threshold and your list queries can be as fast as possible.
Check this out: http://referpages.com/wp/2012/04/101/

OpenERP customers separation

Please I would like to know ho to separate customers in category, since we have two type of customers, the first group should only appear in crm->customers only and vice versa to avoid having a huge list of customers when searching.
My first attempt is to add a tag to different customers to separate them, for example the crm customers have the tag name Mass mailing is it correct to achieve this with tags ?? and my second question how to set default search keyword for example if I click on sales -> customers how to set the default value of search box to for example crmOnly tag thanks.
you can use "domain" where ever you want to have a such a separation.

How do I make a shopping list from multiple recipes in an SQL database?

I'm working on using a recipe database in SQLw, like the one in this question (which has helped a lot already) Structuring a recipe database , to combine the ingredients of several user selected recipes to a shopping list.
Also, the items on this shopping list are to be divided in two categories (eg: "groceries" and "check pantry")
Example case:
User can select 7 recipes to make a weekly mealplan in a form (almost got this part)
The given output is a shopping list of all the ingredients marked as "groceries" and a "check stock" list of all the ingredients marked as "pantry".
Any help at all would be much appreciated!
I had just posted a full solution, but given the subject here looks like it may be homework, I'm just going to point you in the right direction. If this isn't homework, leave a comment and I'll put the full solution back.
Since you have multiple recipes, a normal selection based on joins would give you back multiple rows per ingredient. You want some way to roll up all of the rows for a given ingredient into a single row and show a total of the quantity that you need.

Need Help Writing SQL To Apply Promotions to Shopping Basket at Checkout

Don't laugh but I'm a Lotus Notes (non-relational database!) developer trying to work with SQL and, although I have the basic concepts nailed, I'm stuck on something I'd consider to be "advanced".
Imagine a user reaches an online checkout having added a set of products to their basket. I need to apply promotions to the basket.
These promotions look at the items in the basket and add "points" for any combination that matches a pre-defined "bundle". The promotions also need to be able to target users in specific countries (information gained at point of registration) and other personal details.
The promotions are entered and maintained by the site admin team and need to be as flexible as possible. So they can reward people for things like "Buy X products of type Y and get 50% extra points" or "3 or more XE-123s and get 500 points added" etc.
Right now I'm looking for general direction. How should I store the criteria that matches the items in a basket to any of the running promotions? Would one big Stored Procedure do or should the C# code that builds the basket loop through all promotions and see which fit?
Right now I don't even have a table schema. Just the knowledge of how it should work and little idea where to start.
Jake
My suggestion is to not use SQL for this sort of business logic.
The database is a good place to keep information about products like whether they are type Y or type X. This keeps the database design pretty straightforward.
What you mention about C# seems like a better direction. There is a lot of searchable information about 3-tier architecture that can help explain the benefits of this strategy well.
'As flexible as possible' is a red flag (IMHO). I'd try to nail that down to:
"Fixed-point and/or percentage (of total basket / bundle points) bonus (three columns in a helper table)
When the basket contains a combination that matches a pre-defined 'bundle', where 'bundle' is contained in a helper table, with multiply rows, with a bundleID and a row for each item in the bundle, containing at least ItemID and Quantity.
And no other kinds of reward possible. This to keep the project / requirement manageable.
Then have a SP which checks for the presence of bundles within the basket and applies relevant promotions (as stored in the first helper table).
Also make sure you know the requirement whether 1 or multiple promotions are possible.