This is just a quick question I have about Apple's core data "Recipes" project, so I don't need elaborate answers. When you edit a recipe you can also edit the type. When the type cell is pressed it presents the user with a table view populated by multiple types. How exactly were those types created? I can't seem to find an explanation in the project code or in the .xcdatamodel (I've checked everywhere, and searched it) Also, why does "RecipeType" have to be it's own entity? Why can't it just be part of the "Recipe" entity? Does that have anything do with it?
In this case RecipeType doesn't necessarily have to be its own type, but it is common practice. Using an association like this has many benefits. Say if you wanted to add more metadata per type, you could add it to the RecipeType instead of duplicating a bunch of data throughout your recipes.
It appears that these recipe types are already inserted into the SQLite database Recipes.sqlite. It doesn't appear that they used any of the code in the project to populate this database. It was most likely done using Terminal or some other GUI SQLite editor.
Related
I'm having a little bit of a hard time getting into mvvm. I'm writing a simple app, Notebook. I have one viewmodel, it's name is actually ViewModel. It has an ObservableCollection of Notes inside and methods to save and load those from Isolated Storage. My only Model is Note.cs, it implements INotifyPropertyChanged and I'm of course RaisingPropertyChanged.
I've also got two view, both of them are user controls. One to display list of notes and one to edit the one chosen from the list.
My questions are:
Where do I create an instance of my vievmodel?
How should I implement going from the page with list of notes to the page with detailed view after choosing one Note to edit? At the
moment I'm saving the index of Note in App.xaml.cs, going to the next page and setting
the DetailedView DataContext to the right Note in OnNavigatedTo, but
I don't think it's actually the perfect solution.
Where should I save my Notes? I guess Application_Closing in App.xaml.cs is the right place to do it, but I'd have to have my viewmodel as a global object there, is this the right approach?
Additional question:
I have to add possibility to group notes. I guess that class Group with dictionary (GroupName, howManyNotes) is going to be allright since I don't have to be able to for example write all notes from selected group. Do you think there's a better approach I should think about?
Thanks for respones,
MichaĆ.
I would suggest you take a look at Calibrun.Micro which is a great framework for MVVM. You can get some sample from the CodePlex.
I have used that in a bunch of Project, and will give you flexibility in case if your project grows in size.
Google for Caliburn.Micro sample and you will find a number of sample for all technologies like WPF, Silverlight, Windows Store, Windows Mobile.
Caliburn.Micro CodePlex
I'm new to entity framework and database design and I'm using database first approach, which in visual studio 2012 default to creating POCO classes with DbContext API. I'm trying to keep the POCO classes as lean as possible and I encountered a scenario where I want to generate two types from a single table. My problem is I want to move the navigation properties along with the foreign keys to the derived types. Does anyone know a way to solve this problem?
NOTE: I tried to post an image of what I'm trying to do but apparently I still don't have enough reputation to do that.
Edit: Thanks to whomever gave me enough reputation to post an image. The image that I'm trying to post is below.
Thanks,
Raymond
Did you ever get a solution to this? I have a similar structure. I created a super-type table in my SQL Server DB with 2 sub-type, one has a relationship to another table. EF simply set it up for me. But you should be able to do it by right-clicking on your entity and adding a new navigation item. You can then create a new Association (also by right clicking).
Regards
I added new table to my database and I managed to add it to my data model, using "Update model from database" option. But I cant generate class to acces this table in code. "Add code generation item" results into creating classes for all tables i have in my database.
Well, it seems to be a duplicate, but don't delete this topic at once please, for I've been searching for solution quite a long time and found nothing helpful.
You don't need to add code generation item again if you already did it once. Normally it should be enough to save your EDMX file and generation should trigger. If it for any reason doesn't work, right click on .tt file responsible for generating your classes in the Solution Explorer and select Run Custom Tool from the context menu.
I am trying to learn about core data on the iPhone, and I am looking for a simple Core Data example app.
The problem is, all the example apps I've seen are either too simple (just one view and one data object), or so full of extra functions that it's hard to see what's relevant (Apple's example apps).
I'm looking for an example app with:
an ordinary cascading to-many relationship (e.g. Company > Departments > Employees)
a simple drill-down interface (e.g. click on a company to see list of departments; click on a department to see list of employees; click on an employee to see name and address)
simple editing (press plus for modal view to add company/department/employee)
... so I can learn the basics about passing contexts between views, NSFetchedResultsController etc.
Does anyone know of such a thing?
Thanks!
Try the example found here: Wiley Code Examples
Click on Chapter 18 - Downloads.
Hope this helps.
Let It Be Known
I would recommend Marcus Zarra's Core Data book and the examples therein. He takes one example app that starts off very simple and incrementally adds complexity.
RecipeCT is the project that I would suggest looking at first. Having the book would help you navigate from project to project as the basic Recipes app transforms.
After I've generated the interface/implementation files for entities of a model file in XCode, I've not found a way to keep any custom code (validation methods, etc...) I've added to those generated files, given the scenario where I've added an attribute to a model entity and need to re-generate the interface/implementation files. Does anyone know of a way to make this happen? I've just been doing the copy/paste shuffle, but there has to be a better way.
Assuming that you're only talking about adding methods, and not new instance variables, I'd recommend using Objective C categories to add additional behavior to your model classes. Here's a blog post along the same lines.
Use mogenerator, which uses the Generation Gap design pattern to prevent your customizations from being overwritten when the code is re-generated.