entitykey

How to get first EntityKey Name for an Entity in EF4

僤鯓⒐⒋嵵緔 提交于 2019-12-04 14:26:08
问题 How can I get the 1st EntityKey name for an Entity for Entity Framework 4 because I'm building a repository system and I wanted to get an item by Id (which is the primary key oin EF is the 1st entitykey for the entity) I'm using this code public virtual TEntity GetById(string keyName, Guid entityId) { var entityKey = new EntityKey(this.QualifiedEntitySetName, keyName, entityId); object entity; return this.Context.TryGetObjectByKey(entityKey, out entity) ? entity as TEntity : null; } I want to

How to get first EntityKey Name for an Entity in EF4

一世执手 提交于 2019-12-03 08:42:15
How can I get the 1st EntityKey name for an Entity for Entity Framework 4 because I'm building a repository system and I wanted to get an item by Id (which is the primary key oin EF is the 1st entitykey for the entity) I'm using this code public virtual TEntity GetById(string keyName, Guid entityId) { var entityKey = new EntityKey(this.QualifiedEntitySetName, keyName, entityId); object entity; return this.Context.TryGetObjectByKey(entityKey, out entity) ? entity as TEntity : null; } I want to get the entity key name dynamic. Can anyone help me with this issue? var keyName = this.Context

Entity Framework EntityKey / Foreign Key problem

自古美人都是妖i 提交于 2019-11-28 10:13:51
As the result of a form post, I'm trying to save a new Brand record. In my view, Gender is a dropdown, returning an Integer, which is populated from ViewData("gender") I've setup my link as follows: gID = CInt(Request.Form("Gender")) Brand.GenderReference.EntityKey = New EntityKey("DB_ENTITIES.Gender", "Id", gID) TryUpdateModel(Brand) DB.SaveChanges() Which results in the following error. Entities in 'DB_ENTITIES.Brand' participate in the 'FK_Brand_Gender' relationship. 0 related 'Gender' were found. 1 'Gender' is expected. Could someone explain the parameters in plain english to me. I've also

Entity Framework EntityKey / Foreign Key problem

筅森魡賤 提交于 2019-11-27 03:30:36
问题 As the result of a form post, I'm trying to save a new Brand record. In my view, Gender is a dropdown, returning an Integer, which is populated from ViewData("gender") I've setup my link as follows: gID = CInt(Request.Form("Gender")) Brand.GenderReference.EntityKey = New EntityKey("DB_ENTITIES.Gender", "Id", gID) TryUpdateModel(Brand) DB.SaveChanges() Which results in the following error. Entities in 'DB_ENTITIES.Brand' participate in the 'FK_Brand_Gender' relationship. 0 related 'Gender'