MvcScaffolding: One-to-Many Relationships

 http://blog.stevensanderson.com/2011/01/28/mvcscaffolding-one-to-many-relationships/


Defining more complex relations between model classes

Depending on what data access technology you’re using, there may be many possible ways of defining how models are related together. If you’re using EF Code First, for example, you could be using its fluent configuration interface, which means writing code with statements like “someEntity.HasOptional(x => x.Players).WithForeignKey(x => x.TeamId).CascadeDelete()” and so on.

MvcScaffolding doesn’t know about all of that. For one thing, fluent configuration exists only at runtime (and scaffolding works at design time), and for another, you might be using any data access technology with its own configuration system. You can still use fluent configuration or anything else; just don’t expect scaffolding to know about it.

Instead, MvcScaffolding supports two simple and broadly applicable conventions that will work fine with most data access technologies, including EF. 

 

[ForeignKey("ManagerId")] public virtual Person Manager { get; set; }

你可能感兴趣的:(jquery,.net,mvc,Web,C#,it)