On the web site I am currently working on I decided to give EF4 Code First a shot. It doesn't seem to bad, although not supporting enums means the impressive points are negated by a simple short coming.
Anyway, the problem I have now is that I have a book object which has a collection of authors. When I click on a page where the book is reviewed - an error gets thrown when the book's authors cannot be added to the viewdata - saying the author's collection for this book is null.
so, I navigate to the administration page, go to edit the book, and then suddenly the authors re-appear. So i navigate back to the review page and the authors now appear on this page too.
It looks like they aren't being loaded the first time, but for some reason the admin section causes them to load, so when I head back to the review page it all works fine.
If i happen to do a recompile, and go straight to the review page, they're gone again.
I'm getting my books from the context using CreateObject set - via repository. This method is used both on the admin page and also the review page.
thanks if you are able to help.
To allow lazy loading on POCO class you have to mark your navigation properties as virtual. To force eager loading modify query in your repository and use something like Include("Authors") on queryed ObjectSet.
Just done a little more investigation and I know why it works on the admin page. After debugging through, I found the book's authors collection is initially null. But when a select list is rendered, that contains all the author's in the system, then it gets its authors collection populated.
So in my review action, I retrieve all authors from the repository, without using them in any way, and then my book's collection is also populated.
I guess all this waffling leads to the question: How can I fix lazy loading, or how can I ensure eager loading. I don't think performance will ever be critical and I've had enough faffing with code first now. Think I'll stick to Active record/nhibernate for the time being on other projects.
Related
I may have this completely wrong, but I've been searching available documentation and googling for 2 weeks now, and have my head completely wrapped around the axle.
I am trying to use SpecFlow to write a regression test for our site. This means that I want to exercise all the features so that if we inadvertently broke something, it will catch it.
The site is basically an incident reporting portal. The home page has about 50 different buttons, each of which opens up the data entry pages for a different class of incident.
The data entry pages are arranged in a "wizard" fashion, where it starts with a page of general questions, then moves on to a page of more specific questions and so on. The questions are more or less grouped in the classic "who/what/when/where/why" grouping, with one wizard page for each group, so that we don't overwhelm the user with 100 questions presented all at once.
Exactly which pages are needed depends on the particular type of incident. Some incident types have as many as 8 pages, some as few as 3.
Our specifications for each page are framed in BDD style - Given/When/Then. So it is very natural to translate those specifications into SpecFlow features, and I have done that, at least for the first page of general information questions. But the Scenario had about 30+ steps in it.
I have also written another Feature for testing from the home page -
Given I'm logged in on the home page
When I clicked the button for XYZ ticket
Then it opens XYZ ticket
And the General Information page is displayed.
And I can drive that scenario from a table so that I can test as many different incident types as I want.
So far so good.
But now I want to add
And the General Information page requirements are verified
Where the step definition for that last clause would run the whole scenario for the general information page. In other words, I want to use that other scenario that I have written as a subroutine in this one.
(And then I want to go on and do the same for each of the other wizard pages. But let's get the first one first!)
I can't figure out a way to do that. I tried writing the step definition for the above clause to invoke the step definitions of the General Information scenario, e.g.
Given("I am on the General Information page")
When ("I click this checkbox")
Then ("This happens")
You used to be able to do that (although that would still be a lot of repetition). But now that's giving a warning message that function is deprecated and will be removed (and since I've now upgraded, it may already have been removed - I haven't tried it since I upgraded.) The github issues page (https://github.com/SpecFlowOSS/SpecFlow/issues/1733 has a lot of discussion on it, none of which sheds any light on how to do what I'm trying to do. The primary author (SabotageAndi) seemed to be saying "That's a bad thing; don't do that" without really giving any alternative, at least none that I was able to understand.
Can anyone give me a direction for how to accomplish what I'm trying to do?
I want to use that other scenario that I have written as a subroutine
in this one.
You can't reuse scenarios defined in feature files.
The best you can do is create a new Step that reuse already defined steps by calling them direcly (jameswtelfer comment on 31 Jan in github issue you provide).
I am currently working on an ASP.NET MVC web application using DevExpress controls and I ran into a very annoying issue that I could not fix so far.
I am implementing a page/view which consists of multiple partial views. One of those partial views contains a DevExpress GridView control which contains a so called "DetailRow". This detail row is meant to show additional information about a row when clicking on a small "+" button on the left side of each row. I already use a very similar (basically almost identical) GridView inside of a DevExpress "PopupControl" on another page of my website without any problems, but on the new page I am currently working on it just does not work.
The page actually loads just fine when I open it, but as soon as I click on the small "+" in a row my controller's Index-method is called and I do not understand why. On the other page which has the GridView inside a PopupControl, only the method for the partial which contains the GridView and the method for the actual content of the DetailRow is called, which is what I would expect to happen on my new page as well.
I have already recorded the network communication between the site and the server and I do not see any GET request either which would result in the Index-method getting called. There is only a POST for the partial which contains the GridView. I also get the following DevExpress-specific error logged in the console when this happens:
Invalid server response. It is required that a Partial View contains
only the extension definition code, without any additional markup. To
learn more, see https://www.devexpress.com/kbid=KA20010.
Unfortunately the linked article in that error did not help me figure out the problem either. It talks about making sure that all extensions are defined in a separate PartialView with no extra tags but I already have it like that, there are no extra tags anywhere in my partial views. I also do not assign a unique SettingsBase.Name value so that cannot be the problem either.
Does anyone know what is going wrong here or how I can further debug the problem? I do not know any way of finding out why the Index-method of my controller is being called so I have no clue what to do.
I just managed to find the solution for my problem. There was something wrong with my routing so the POST request I mentioned in my question was routed to the wrong controller. I fixed the routing and now everything works as expected.
I'm new in Rails, I have a Meal model which has many Products. Meals are assign to User (maybe this is important for a concept). In meals/new.html.erb I want to create new Meal as follow:
Click the button "Display Products"
On the same page (meals/new.html.erb) open modal (pop-up) with all products assigned to current user ( I have help method for current-user). It should be displayad like a list or grid with checboxes for example.
Then user can check few products and click "Confirm".
After that in meals/new.html should be appeared list of chosen products with additional input to fill their quantity.
So I have two problem here.
How should I display modal? Is needed any Ajax (I'm not so familiar with this technology)
How can I pass products between view and modal?
Could you help me a little to achieve these goals?
Regarding your first problem, displaying the modal is fairly straight forward. Essentially you will create a div with the proper bootstrap classes to be hidden when the page is loaded, and then create a button that makes it visible. I would recommend either reading over the W3Schools entry on modals, or from the appropriate part of the bootstrap javascript documentation.
Regarding your second question, this depends on exactly what you mean. The modal is part of the view, so if you're only trying to put information that is currently on the modal back onto the "page" behind it, you can do so fairly simply with javascript (copying content out of one element into another, or updating states of inputs). If, on the other hand, you're trying to use the modal to retrieve information from the server (for instance if you wanted to show a list of possible options, and then display detailed information about the selected items from the database) that would require Ajax.
If you have any snippets of code that aren't functioning as you expect, feel free to add your View to the question. In cases like this, usually the best way for us to provide help is for you to take an early crack at this, post the relevant code, and then seek answers for the things that behave unexpectedly.
I hope that helps.
Hopefully someone could shed some light on where we're going wrong here. Our implementation is using Paypal but having set up the integration as described in the docs (http://docs.ucommerce.net/ucommerce/v5/payment-providers/setup-paypal-standard-website-payments-as-a-payment-method.html) attempting a payment was resulting in a plain postback at the "Preview" stage (i.e. click to pay but page posts back and nothing happens).
My understanding is that somewhere in the pipeline the uCommerce_Payment table must be populated for the PurchaseOrder in question and from there the following code (in uCommerce/Preview.cshtml)...
TransactionLibrary.ExecuteBasketPipeline();
TransactionLibrary.RequestPayments();
...should pick up the entry in this table and direct the payment accordingly.
Problem is, when I check the database there are no records in our uCommerce_Payment table.
Any ideas?
Sometimes at websites all comments or other data from DB is hidden by default. When user click at link like "Display comments" all comments from database are dynamically selected and placed under the content. It must be great for mysql performance, because content is generated only when user excatly need it. I would like to implement this stuff at my app.
I've got one idea to do this so far. Remote action with #comments = Content.comments and next page.insert_html at RJS template. Is it good idea or maybe I should choose different way?
The decision is purely based on the application that you are developing. For example if in case of stack overflow it does not make sense to show only the question and show answer link. But in case of a blog post it may be fine.
In the above situation, I don't think there will be a good improvement in performance by removing the comments of the content on show page. We can achieve the same functionality by making use of javascript methods. Hide the content on page load and show in on client request.