How to create an EntityKey in Entity Framework
They are 4 ways to create an EntityKey using an EntityKey class. EntityKey class has four overload constructors and of them, one overload constructor supports composite keys.
In this article, I will explain how to create EntityKey using the following two constructors.
1.EntityKey(String, IEnumerable<KeyValuePair<String, Object>>)
To create an EntityKey using the above constructor, we need to pass entity set name and a generic KeyValuePair IEnumerable collection. Using this constructor, we can create composite keys.
2.EntityKey(String, String, Object)
To the above constructor, we pass an entity set name and specific key name and key value. This example is one usage of EntityKey class. The below example code creates an instance of EntityKey using a specified key name, key value, and the qualified entity set name.
In this article, I will explain how to create EntityKey using the following two constructors.
- EntityKey(String, IEnumerable<KeyValuePair<String, Object>>)
- EntityKey(String, String, Object)
1.EntityKey(String, IEnumerable<KeyValuePair<String, Object>>)
To create an EntityKey using the above constructor, we need to pass entity set name and a generic KeyValuePair IEnumerable collection. Using this constructor, we can create composite keys.
2.EntityKey(String, String, Object)
To the above constructor, we pass an entity set name and specific key name and key value. This example is one usage of EntityKey class. The below example code creates an instance of EntityKey using a specified key name, key value, and the qualified entity set name.
More Resources
- POCO class in Entity Framework
- POCO vs Entity Objects with comparison table
- Rules to be followed while creating POCOs - 4 important rules
- How to create a POCO class, integrate with ObjectContext, executing a query with POCOs
- How to load related POCO entities - loading patterns and their differences in their usage with examples
- How to perform Lazy Loading with POCO classes
- What is Change tracking in POCOs, ways of tracking
- Snapshot change tracking with DetectChanges() method
- Change tracking with proxies, How to create proxies?
- Instantiate POCO classes using ObjectContext.CreateObject method
- Using the DetectChanges() method to Fix-up Relationship in poco entities
- Entity Framework EntityKey object
- Retrieving a single entity with GetObjectByKey method of ObjectContext using EntityKey
- Loading Related entities in EF
- How to change the state of an entity using ChangeObjectState method of ObjectStateManager
- ChangeState method of ObjectStateEntry class
- Update an entity in a disconnected scenario using ApplyCurrentValues method
- Using ApplyOriginalValues method
- ObjectStateEntry class
- Entity state in Entity Framework - what, how, why?
- AcceptAllChanges and SaveChanges methods in Entity Framework
Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls
VB .Net
Constructors in Visual Basic.Net