entitykey

Entity Framework EntityKey / Foreign Key problem.

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) ...

ASP.net MVC: Where in my design should I create/declare entity keys?

When creating a new entity object that has a foreign key value I need to create a new Entity key (Entity Framework in .net 3.5) for the object, but I'm having trouble deciding where in my application I should do this. Right now when I create a new record with a foreign key, I create the entity key in the controller (in this case a user ...

EntityReference has an EntityKey property value that does not match?

I am attempting to add some entities that I have created. When I try and add the entity in question to the set (see code below) I get the following error: "The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object." I can't tell what entitykey...

How to get the value of EntityKey?

How to get the value of EntityKey? I tried: String x = Customer.EntityKey.EntityKeyValues[0].Value; String x = Customer.EntityKey.EntityKeyValues[0].Value.ToString(); String x = Customer.EntityKey.EntityKeyValues; String x = Customer.EntityKey.EntityKeyValues.ToString(); Ended up with: Object reference not set to an instance of an ...

Accessing foreign key value (int) in Entity Framework

Hi there, I just spent the last 3-4 hours trying to retrieve a foreign key value using linq to entities and a stored procedure. Any advice is much appreciated. public JsonResult GetEvents(double? start, double? end) { AnoEntities _dbAno = new AnoEntities(); var events = _dbAno.Events_GetByDateRange(fromDate, toDate...

Update one-to-many EntityKey using Foreign Key

To use by the easiest way Entity Framework, I use partial class to add Foreign Key on most important Entities Model. For example, I have an Entity "CONTACT" which have "TITLE", "FUNCTION" and others. When I update a CONTACT, with this code, Foreign Key are automatically updated : public int? TitId { get { if (this.TITLE...

How to get first EntityKey Name for an Entity in EF4

Hello, 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 ent...