Adding Relationships between views in Devart entity framework - entity-framework-4

I want to have a relation between views in EF. I am following this post to modify it in the xml file.
http://smehrozalam.wordpress.com/2009/08/12/entity-framework-creating-a-model-using-views-instead-of-tables/.
I am getting error,
Custom tool error: Multiplicity is not valid in Role 'VIEW' in relationship 'FK_'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be 1.
I am not really sure if I am going the right path.
The main goal of doing this is to use this entity over oData, and have links to the Ids in the view. I am not using the tables directly, because the table has Ids and I want the names to be sent back to the client. The relationship should give the child details.
If there is any other way to achieve this, please help!!
Thanks in Advance

Related

tableview from multiple core data entities swift

I am struggling with something I think should be basic but cannot figure out. I have two entities in core data with a one to one and one to many relationship. They are Company which can have multiple Opportunities.I want to load a table view listing the opportunities (sorted by name) with their associated companies. Can this be done by simply accessing the Opportunity entity? If so, how do I access company? The Opportunity class references it as a "Company" type and so I tried to go using dot notation through to company.companyName but it failed on that, and if I change it to simply company (of type Company) it does show .Company: and other reference data but not the simple name field I am looking for. This seems as if it should be simple but...........
This was simple and I was overlooking the ability to load the fetchedresultscontroller with the right type (in my case the Opportunity class) and then use dot notation from there. I was trying to do it with key value access which did not work. Cheers

CoreData: Create a new entity to be parent of old entities

Recently, I am trying to refine my code. I found that all my entities has attributes named identifier and owner, so I want to create a entity to be their parent which contains identifier and owner.
Following is the result, all object inherit from a parent named SRModel, which has identifier and owner attributes.
However, after I delete all these redundant properties, the persistent store is not able to auto migration.
How can I solve the problem? Do I have to do migration by myself?
Are there any simple way to do so?
According to Apple's Core Data Model Versioning and Data Migration Programming Guide, you can't do that automatically.
You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination
Note Andy Riordan's point about inheritance. And don't just take his word for it; look at the generated .SQLite files yourself under the old and new models. Adding a parent entity with only two common attributes will just make your entities, and backing tables, larger, with no performance benefit. If you really want to note the two common elements, use a Protocol to call them out.

Core Data difference between parent/child and to-one/to-many inverse relationships

I've looked all over SO, youtube, and the Apple docs and am having real trouble understanding the distinction--if any--between parent/child and to-one/to-many inverse relationships in Core Data. Nothing I've found appears to address the subject directly and explicitly.
I need to know this because I want to load a table view with data from one entity, called ListActivity, grouped into sections defined by another entity called ListCategory, as shown here. Also not real confident of my naming convention:
Can someone please clearly explain the difference--and when to use each case--or point me to something that can?
Thanks!
Edit for clarification:
For comparison, here is a screenshot of my entities with ListCategory specified via the menu in the Data Model Inspector as the Parent Entity for ListActivity:
Relationship is used go down in an object graph (i.e activities in a category) while an inverse relationship is used to go up in an object graph (i.e category to which an activity belong to).
While naming convention looks fine. better use "activities" instead of "listActivities" and "category" instead of "toCategory".
Generate classes for them and you'll better know how these will work out.

How to get data from 2 entities in MVC ?

I am developing MVC application and using razor syntax. I have used model first method.
I have two entities, Customer and Lead. Lead is inherited from Customer.
When IsActive property is true then Customer treated as a Lead, otherwise it will be a customer.
Please check edmx file image.
Now, In regular entities we just deal with single entity and single table.
In this case how can I handle , Save and Load process. beacuse I have to store and load the record from 2 tables of DB.
Is Regular Index View will work here ?
When using inheritance in the Entity Framework you will have a single DbSet on your DbContext that exposes your hierarchy. In your database you have several options for configuring your table structure. For example you can use:
Table per Hierarchy
Table per Type
Table per Concrete type
(See this blog for a nice explanation: Inheritance in the Entity Framework.
In your queries however, you don't have to think about this. Your queries will have the following structure:
var leads = from l in dbcontext.Leads.OfType<Customer>()
select l;
The OfType() filters your collection to a subtype in your hierarchy. If you skip the OfType you will get both customers and leads in your resulting query.

Entity Framework 4.0 2 many-to-many with same entities

I have 2 entities (say People and Books) that have two many-to-many relationships. I have created two different linking tables - e.g. the linking tables are called BooksCheckedOutByPeople and BooksOnHoldByPeople.
EF 4.0 correctly makes two relationships. It calls them something like PeopleBooks and PeopleBooks1.
When I am making Linq queries, how do I tell Linq to use a specific one of these relationships? Is there any way in Linq to specify one relationship instead of the other?
Say I'm creating a query against People and I want to get the Books for BooksCheckedOutByPeople and thus I need to use the relationship PeopleBooks.
Thanks.
You should be able to rename "PeopleBooks" and "PeopleBooks1" to more informative property names by editing the model EF generates for you. Something like "BooksOnHold" and "BooksCheckedOut".
At that point, when writing your LINQ queries, just reference the right navigation properties (as they're called). LINQ uses whichever properties you specify, and the Entity Framework should generate a unique navigation property for each collection.
Edit
I just fired up VS2010 to copy your model and poke around a bit.
I see that EF4 did indeed generate two Navigation Properties foor Book and Person, called People and People1, and Books and Books1 (respectively).
If you select any of these Navigation Properties in the Model Browser and look at the Properties pane, you should be able to see which table is correlated to that association and rename the property appropriately. Here's a screenshot from my PC:
You can see that I've selected the "People" nav property for the "Book" entity. The association in this case is determined by BooksCheckedOutByPeople, so I can rename the property to "PeopleCheckingOut", or something more useful than "People". When I'm using LINQ-to-Entities later, I then reference the "PeopleCheckingOut" property to query that collection on any specific Book.

Resources