English 中文(简体)
利用关系 首先是现有的数据库
原标题:Relationship Using Code first with Existing database

在界定“

    public class Product
    {
        public int ProductId { get; set; }
        public string Name { get; set; }
        public Category Category { get; set; }
    }

    public class Category
    {
        public int CategoryId { get; set; }
        public string Name { get; set; }
        public ICollection<Product> Products { get; set; }
    }

我能否不把导航财产列入第13类?

最佳回答

If you just want it infered by code first convention then yes you need both on either side. I d also make the collection "virtual" to support lazy loading.

在建立模型时,你可以使用流体组合来建立这一模型。 这将是这样的事情。

modelBuilder.Entity<Product>()
    .HasMany(x => x.Category) 
问题回答

暂无回答




相关问题
Core Data Relationship Fault

Tracking a familial relationship in Core Data (1 parent entity + 2 types of children, one of which is recursive), trying to create a drop-menu in Interface Builder that lists the names of the parent ...

Eager Loading on tracked items?

I have an element bound to an entity (Contact) that exposes some navigation properties. I want, that on some action (i.e. a "Load children" button), the Contact should load for all its children and ...

Simple relational problem

I m using entity framework with 3.5 sp1, and I ve come across a strange problem. I have a 1 to many relationship and I cant seem to add a value for it. I have a table "Bookings" and FK in table "...

Map relationship with Entity Framework

Maybe im just an idiot, but I am having serious issues mapping relationships with the new entity framework. When using LinqToSql, you would just right click the table, add association, select the ...

How do I Relate these 4 Tables

Trying to setup a simple Thread/Poll table mapping. Here is what I have: Threads table ThreadID (Primary Key/Identity Column) Polls table PollID (Primary Key, FK for ThreadID for one-to-one ...

Undelete an entity marked as EntityState.Delete?

instead of talking let me talk with code: Dim Contact = Context.Contacts.Include("Phones") Dim phone = Contact.Phones(0) Contact.Remove(phone) How do I refresh the context now, canceling last ...

Delete a relationship?

What is the opposite of: Dim ad As New Address Person.AddressReference.Attach(ad) I mean how do I delete the Person.Address? (both with deleting and without - meaning only delete the relation)?

热门标签