Monday 15 February 2010

c# - Adding "key" attribute to properties in a base class in MVC 4 for Entity Code First -


I have a del in which there is a square in which there is a list of items (this is from metadata, T source code Is):

  public class APIKeyInfo {public APIKeyInfo (); Public long accessmask {get; Set; } Public listing & lt; AccountEntry & gt; Character {receive; Set; } Public Date Expired {Received; Set; }} Public Class Account Entry {Public Account Entry (); Public long spectrum {received; Set; } Public string name {get; Set; } ... other properties}   

Now in my code, I have an extended class of APIKeyInfo, which specifies a database table using the EF code:

  [table ("MyPK")] Public Class MyAPI: APIIEFO {{Key] Public Intake {Received; Set; } [Required] public string vCode {get; Set; }}   

The problem is that the easf tells me to give an error that when it runs on the API table at the APIKeyInfo (the "I listed on the list" tries to create the table) property on the MAPK FK), it says that the key has not been defined. So, my question is, how can I specify the key to the "list characters" property when I do not access the source code? I hope for something like:

  [Table ("MyPK")] Public Class Mykey: APIKeyInfo {[Key] Public int KeyId {get; Set; } [Required] public string vCode {get; Set; } [Key] basis. Character. Character id; }   

Just tell which property to use, but obviously it does not work.

I have not really tried to do this, but I do not know why this will not work . Instead of using properties, try to use EntityTypeConfiguration objects ...

  Public class MyApiKeyMapping: EntityTypeConfiguration & lt; MyApiKey & gt; {Public MyApiKeyMapping () {this.ToTable ("MyApiKey"); this. Haski (K => KKIID); this. Property (P => P. Vcode) .IsRequired (); }} Public class accountantremruppapping: entity type configuration & lt; Accountantry & gt; {Public Accountantry Mapping () {this.ToTable ("Accountantry"); this. The Husky (k = & gt;.}}   

Which should you create a mapping for the entities that you do not own (hopefully).

Then in your reference you simply add the following.

  public class MyApiContext: DbContext {... protected override void OnModelCreating (DbModelbuilder Modlbilder) {modelBuilder.Configurations.Add (new MyApiKeyMapping ()); Modlbilder. configuration. add (new Khataintry mapping ());}}   

have relationships to set mapping And can also add other properties.

No comments:

Post a Comment