Logo
PREGNANCY
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows 7

Visual Basic 2010 : Serialization in the ADO.NET Entity Framework

6/14/2011 9:16:17 AM
When you create Entity Data Models, entities are automatically decorated with Serializable and DataContract attributes and their members as DataMember as you can easily check by investigating the code-behind file for EDMs. This enables binary and Xml serialization for entities also in WCF scenarios. To understand how this works, create a new console project and add a new EDM wrapping the Northwind database , including only the Customers and Orders tables. Basically you use formatters as you did in the objects serialization with no differences. Code in Listing 1 shows how to accomplish this.
Listing 1. Serializing Entities from an Entity Data Model
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO

Module Module1
Sub Main()
Using northwind As New NorthwindEntities
'Retrieves the first order, as an example
Dim anOrder As Order = northwind.Orders.Include("Customer").First

'Same as classic objects serialization
Dim formatter As New BinaryFormatter
Using stream As New FileStream("C:\temp\EFSerialization.dat",
FileMode.Create)
formatter.Serialize(stream, anOrder)
End Using

Dim newOrder As Order
Using source As New FileStream("C:\temp\EFSerialization.dat",
FileMode.Open)
newOrder = CType(formatter.Deserialize(source), Order)
End Using
End Using

Console.ReadLine()
End Sub
End Module


Other -----------------
- Visual Basic 2010 : Serialization in Windows Communication Foundation
- Microsoft Excel 2010 : Creating and Modifying Charts - Selecting Chart Elements & Formatting Chart Elements
- Microsoft Excel 2010 : Creating and Modifying Charts - Changing a Chart Type & Changing a Chart Layout and Style
- Microsoft Visio 2010 : Serialization with XAML
- Microsoft Visio 2010 : Custom Serialization
- Microsoft Visio 2010 : Connecting Shapes with Dynamic Connectors
- Microsoft Visio 2010 : Copying and Pasting Shapes & Connecting Shapes with Lines
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Creating Office Documents on Windows Live
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Setting Folder Permissions on Windows Live
- Visual Basic 2010 : XML Serialization
- Visual Basic 2010 : Objects Serialization (part 2) - Soap Serialization & Providing Serialization for Custom Objects
- Visual Basic 2010 : Objects Serialization (part 1) - Binary Serialization
- Microsoft Excel 2010 : Editing a Chart & Moving and Resizing a Chart
- Microsoft Excel 2010 - Choosing the Right Type of Chart & Creating a Chart
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Working with Folders on Windows Live
- Microsoft PowerPoint 2010 : Working Together on Office Documents - Accessing Documents on Windows Live
- Microsoft Visio 2010 : Creating a New Diagram - Selecting Shapes
- Microsoft Visio 2010 : Creating a New Diagram - Using Basic Shapes and the Dynamic Grid
- Managing Security in Windows 7 : Windows Firewall
- Managing Security in Windows 7 : Designing BitLocker Support
 
 
Most view of day
- Working with E-mail, Contacts, and Events : Create a Contact Category
- Windows Phone 8 : The Multimedia Experience - Xbox Music Pass (part 2) - Playing Music from the Xbox Music Pass
- Microsoft Visio 2013 : Adding Sophistication to Your Drawings - Positioning shape text
- Using the Windows 7 Libraries : USING THE EXPLORER BROWSER CONTROL (part 2)
- Microsoft Excel 2010 : Inserting Blank Rows (part 1) - Separating Subtotaled Rows for Print
- BizTalk Server 2009 : Building a Resequencing Aggregator
- Working with the User State Migration Tool (part 3) - Gathering Data by Running ScanState
- Windows Phone 7 : 3D Game Development (part 4) - Rendering 3D Models
- Microsoft Visio 2010 : Modifying a Graphic (part 2) - Wrapping Text Around a Graphic
- SQL Server 2012 : Running SQL Server in A Virtual Environment - AN OVERVIEW OF VIRTUALIZATION
Top 10
- Microsoft Access 2010 : Report Properties and Why to Use Them, Basing Reports on Stored Queries or Embedded SQL Statements
- Microsoft Access 2010 : Working with Sorting and Grouping (part 2) - Sorting and Grouping Settings
- Microsoft Access 2010 : Working with Sorting and Grouping (part 1) - Add Sorting and Grouping to a Report
- Microsoft Access 2010 : Building Reports Based on More Than One Table (part 3) - Working with Subreports
- Microsoft Access 2010 : Building Reports Based on More Than One Table (part 2) - Build a One-to-Many Report by Using the Report Wizard
- Microsoft Access 2010 : Building Reports Based on More Than One Table (part 1) - Build a One-to-Many Report by Using the Report Wizard
- Microsoft Access 2010 : Building Powerful Reports - Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Building Powerful Reports - Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Building Powerful Reports - The Anatomy of a Report
- Microsoft Visio 2013 : Adding Sophistication to Your Drawings - Grouping shapes
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro