Views does not import to Entity Framework - entity-framework

I have a few views in my database that im using in my ASP MVC-application. Now I am experiencing a very strange problem. There are 8 views in the database but even if I check them all in the Create Enity Data Model-guide only 7 of them are available as objects in the datacontext.
If I try to import ONLY the view that gets left out I get an empty model.
Is there some kind of limitation that I dont know of? Or is this a known problem?

Sounds like there is something special with this view. Things to check:
Are the rights the same on this view as others?
Try running a select on this view from query manager to confirm that it works
Open up the "empty" model in an xml view and see if there are any error messages in it

I have ran into issues importing tables and views with no key defined. The entity framework will try to assign one automatically if it can, but if you have duplicate data you may have to create a primary key before EF will bring it in.

That didnt do the trick. I removed all joins from the view definition and added a very simple view (basically just a select from a single table). That worked. Then I added the joins one by one and made the view more complicated for each step. Now I have the same view as I had before I started this process and I can now import it without problems. Something is strange in the state of Denmark

Related

Can I delete/edit Models after they've been created through the GUI?

Typically I build up the models, then loop back and put the relationships in. It seems that I cannot do that in the GUI. I also cannot create a model without a migration, and then create the migration once I've 'fine-tuned' the model. Any advice? I also noticed that CRUDs is greyed out in the menu at the top. Is it possible I loaded something incorrectly?
-Regards

How to compile view in postgres

Is there any alternative in postgres to compile views as oracle? I searched ,but couldn't find any relevant alternatives for it . Can anyone suggest on this?
ALTER VIEW employee COMPILE; in oracle
In PostgreSQL views don't have to be compiled.
This is an Oracle specific nuisance. Oracle does not make sure that the dependencies of a view remain intact, so it can happen that a view becomes invalid because one of its requisites changed or vanished.
Oracle calls such a view invalid and calls the process of making sure all requisites are there compile.
In PostgreSQL, the database management system will prevent you from changing the requisites of a view in a way that might break the view, so a view can never become invalid. Hence there is no need to check its validity.
This is convenient, but it comes at the price that you have to drop and recreate the view if you want to modify an underlying table.

edmx context loses views mapping

all.
I am using entity framework and I am trying to add three new tables to my context. The problem is, I go to "Update Model From Database", select the tables and after the new tables are added in the context, my entities which refer to views, they lose mapping!
Then, I click on the entity, then on "Mapping Details" and when I click on "Maps to" I cannot see the views anymore, only the tables.
Where did the views go? Why did they lose the mappings? What do I do to solve this issue?
Best regards.
I still do not know why the views vanished when I updated my data model, but now I got my solution working.
What I have realized is that even if I created a new context and added only the views, they were not added! (Still I don't know why).
What I did to solve this issue was: I copied the XML file, where I had all my views, tables, etc. Then, I updated my context, adding the tables I needed. After that I edited the new XML file, adding the views' code.
This solved my issue. It's not ideal, but it solve.

CoreData Relationships in two different ManagedObjectContexts

Warning: This is my first IPhone Application and I'm new to Objective C, therefore my question might be very basic.
Actually I have a conceptual problem:
I have a one to many relationship between my NSObjects Project and WorkTime (Project<-->>WorkTime). WorkTime has attributes like startDate, endDate, … and a relationship named project to the Project object.
On the UITableViewController subclass that shows my list of WorkTimes, I fetch the CoreData Model with a FetchedResultsController. When I create a new WorkTime, I use a second context and merge it with the "default" once, once the user has clicked on "save" on the drill-down View, like in the CoreDataBooks example from the Apple Documentation. That works well.
The problem starts when I set the relationship. Since the projects are in the “default” context, I can’t assign any project object to the project key in WorkTime, since they are in two different contexts.
So, should I copy all the projects into the “saving” context? Or should I use just one context for everything?
One problem that arises when I use only one context is that the tableview that shows the WorkTimes gets actualized when the user clicks on the addbutton (insertNewObjectForEntityForName). So the list grows right before it presents the new view controller (addWorkTimeDetail) in modalviewcontroller. And if the user clicks cancel in that detail view and decides not to save the WorkTime, I’d have to delete the newly created entity from the context. I don’t think this sounds the way to do it.
Suggestions would be very appreciated!
UPDATE
I'm still having some issues:
When the AddWorkTimeViewController is created from the RootViewController, I create a new NSObject WorkTime. When the user clicks "cancel" I delete the newly created WorkTime and return to the RootViewController. The FetchedResultsController actualizes the tableView and I see a short animation that comes because the object has been deleted. That's doesn't look nice.
I know it would be better to create the object ONLY if the user clicks "save" and by "cancel" do nothing, but I need that object in order to populate the drilldown views with values. The drilldown views work with a NSManagedObject. I see two possible ways to solve this:
1) Have a temporary object TempWorkTime subclassed from NSObject with the same attributes from the WorkTime NSManagedObject. I would create the TempWorkTime in the AddWorkTimeViewController and use it for the drilldown views. I would of course have to subclass them to accept an NSObject instead of a NSManagedObject. I guess type casting wouldn't work. When the user clicks "save", I would create a WorkTime NSManagedObject and pass it the values from the TempWorkTime.
2) Is it possible to trick the FetchedResultsController so that it doesn't update itself while the tableView is not visible? In that case, it would not respond to the changes in the context until it's back in view, and so it would not do the delete animation.
Any suggestions?
SECOND UPDATE - maybe it's useful for people trying to do this same thing
I found this link which proved to be very helpful:
http://www.timisted.net/blog/archive/multiple-managed-object-contexts-with-core-data/
It's very well explained why it's sometimes a good idea to use two contexts. I had some problems with using one context explained in the UPDATE part of my question.
Now I'm using two contexts and it works perfectly, even with relationships. Important is to use the NSManagedObjects of the second context when creating the relationship. That was my mistake when I started to work with this approach.
I don't see why you use two different contexts.
The way to do it is to pass your tableView's context to addWorkTimeDetail, and add any new WorkTimes to that context. If the user cancels, i.e. doesn't create a new object, there will be nothing new in the list when you return. If the user creates the new WorkTime in the context it was passed, it will show up in the list when you return.
In your example, use only one context, and pass it along to your subviews.
I found this link which proved to be very helpful:
http://www.timisted.net/blog/archive/multiple-managed-object-contexts-with-core-data/
It's very well explained why it's sometimes a good idea to use two contexts. I had some problems with using one context explained in the UPDATE part of my question.
Now I'm using two contexts and it works perfectly, even with relationships. Important is to use the NSManagedObjects of the second context when creating the relationship. That was my mistake when I started to work with this approach.

Question regarding iPhone core data and how to duplicate features for multiple users...that doesn't make sense, just read my question :)

So I am working on a simple iPhone app, that uses core data to manage objects. My code is similar in function to Apple's CoreDataBooks app, found here. There is a blank UITableViewCell, and you have the ability to add objects to this blank list. If you hit the add button, a DetailViewController pops up that manages the attribute of each object. In the coredatabooks example, the app is like a library, and you can add book objects. My question is about how I might go about making it so that multiple users can have their own separate list of these objects. Again, relating back to coredatabooks, you would be able to make different library objects whose attributes are the book objects themselves. So using the convenient and easy to use coredata ui, would it be very hard to set it up so that in the UITableView, there was Library-A and Library-B and then selecting one of the libraries would move me to a screen that has the list of different books unique to that specific library? If you then select a book, you would then be able to view that book's attributes as before. So I guess my question is regarding how to put another RootViewController-esque view in front of the native one. As you may gather from this post I am in the learning stage of iPhone development, so I don't even know if logically this is even feasible or the correct way to do it. Any help/insight on this matter would be greatly appreciated! Thanks for your patience!
Create another UITableViewController (.h, .m, .xib files). And you can put some functionality into that view controller for adding library.
You can set that viewcontroller as startup object from MainWindow=.xib file. OPen that xib file -> expand navigation controller -> click on root view controller.
then in attributes window you can select your new controller as startup. you have to also set startup class from identity window.
Ruchir is correct, you can add another table view and controller. You will have to make some adjustments so that it is loaded and displayed first.
Also, it sounds like you will want to create a new entity in your data model for a Library which should have a to-many relationship with the Book entity.
Library <-->> Book
The new table view controller can use a fetched results controller that fetches Library entities. When the user chooses a row, you can set a property on the books table view controller before you push it on the navigation stack. Then use a predicate on the books fetched results controller to only fetch books in that library.