Entity Framework TutorialJoydip Kanjilal
download
https://ebookbell.com/product/entity-framework-tutorial-joydip-
kanjilal-4633638
Explore and download more ebooks at ebookbell.com
2.
Here are somerecommended products that we believe you will be
interested in. You can click the link to download.
Entity Framework Core In Action Second Edition Jon P Smith
https://ebookbell.com/product/entity-framework-core-in-action-second-
edition-jon-p-smith-57414396
Entity Framework 40 Recipes A Problemsolution Approach Larry Tenny
https://ebookbell.com/product/entity-framework-40-recipes-a-
problemsolution-approach-larry-tenny-2310094
Entity Framework 4 In Action Pappsc Stefano Mostarda Marco De Sanctis
https://ebookbell.com/product/entity-framework-4-in-action-pappsc-
stefano-mostarda-marco-de-sanctis-2321734
Entity Framework 41 Experts Cookbook Devlin Liles Tim Rayburn
https://ebookbell.com/product/entity-framework-41-experts-cookbook-
devlin-liles-tim-rayburn-2614594
3.
Entity Framework 6Recipes 2nd Edition Brian Driscoll Nitin Gupta
https://ebookbell.com/product/entity-framework-6-recipes-2nd-edition-
brian-driscoll-nitin-gupta-4569854
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
https://ebookbell.com/product/entity-framework-core-cookbook-2nd-
edition-ricardo-peres-5853398
Entity Framework Core In Action 1st Edition Jon Smith
https://ebookbell.com/product/entity-framework-core-in-action-1st-
edition-jon-smith-7144114
Entity Framework 6 Recipes Second Edition Driscoll Briangupta
https://ebookbell.com/product/entity-framework-6-recipes-second-
edition-driscoll-briangupta-11810994
Entity Framework Core Kenji Elzerman
https://ebookbell.com/product/entity-framework-core-kenji-
elzerman-59128464
6.
Entity Framework Tutorial
Learnto build a better data access layer with the
ADO.NET Entity Framework and ADO.NET
Data Services
Joydip Kanjilal
BIRMINGHAM - MUMBAI
Credits
Author
Joydip Kanjilal
Reviewers
Bogdan Brinzarea-Iamandi
StefanTuralski
Senior Acquisition Editor
Douglas Paterson
Development Editor
Ved Prakash Jha
Technical Editor
Ajay Shanker
Editorial Team Leader
Mithil Kulkarni
Project Manager
Abhijeet Deobhakta
Project Coordinator
Lata Basantani
Indexer
Monica Ajmera
Proofreader
Joel T. Johnson
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
[FM-3]
9.
About the Author
JoydipKanjilal is a Microsoft MVP in ASP.NET. He has over 12 years of industry
experience in IT with more than 6 years in Microsoft .NET and its related technologies.
He has authored many articles for some of the most reputable sites like,
www.asptoday.com, www.devx.com, www.aspalliance.com, www.aspnetpro.com,
www.sql-server-performance.com, www.sswug.com, etc. Several of these articles
have been featured at www.asp.net—Microsoft's Official Site on ASP.NET. Joydip was
also a community credit winner at www.community-credit.com a number of times.
He is currently working as a Senior Consultant in a reputable company in
Hyderabad, INDIA. He has years of experience in designing and architecting
solutions for various domains. His technical strengths include C, C++, VC++, Java,
C#, Microsoft .NET, Ajax, Design Patterns, SQL Server, Operating Systems, and
Computer Architecture. Joydip blogs at http://aspadvice.com/blogs/joydip
and spends most of his time reading books, blogs, and writing books and articles.
His hobbies include watching cricket and soccer and playing chess.
Writing a book is always a rewarding experience. My special thanks
to Douglas Paterson for providing me the opportunity to author this
book—turning this idea into a reality. I am also thankful to the entire
Packt team for their support.
I am also thankful to Abhishek Kant (Microsoft), Steve Smith
(AspAlliance), Russell Jones(DevX), Steve Jones(SSWUG), Jude Kelly
(SQL Server Performance), and Anand Narayaswamy (AspAlliance)
for their inspiration and support. My heartiest thanks to my friends
Tilak and Vinod for their continued encouragement.
My deepest respects and gratitude to my parents for their love,
blessings, and encouragement. My thanks to my other family
members too, for their support, and to little Jini in particular, for her
continued inspiration and love.
Thank you all so much!
[FM-4]
10.
About the Reviewer
BogdanBrinzarea-Iamandi has a strong background in Computer Science
holding a Master and Bachelor Degree at the Automatic Control and Computers
Faculty of the Politehnica University of Bucharest, Romania. He also holds an
Auditor diploma at the Computer Science department at Ecole Polytechnique,
Paris, France. His main interests cover a wide area from embedded programming,
distributed and mobile computing, and new web technologies.
Currently, he is employed as Supervisor within the team of Alternative Channels
Sector of the IT Division in Banca Romaneasca, a Member of the National Bank
of Greece. He is Project Manager for Internet Banking and he coordinates other
projects related to new technologies and applications to be implemented within the
banking area.
Bogdan is also the author of two AJAX books, the popular AJAX and PHP: Building
Responsive Web Applications and Microsoft AJAX Library Essentials, also by Packt.
[FM-5]
12.
Table of Contents
Preface1
Chapter 1: Introducing the ADO.NET Entity Framework 7
What You should Know 8
Looking Back 8
What is ADO.NET Entity Framework? 9
Is It Just Another ORM? 9
The ADO.NET Entity Framework Architectural Components 10
The Entity Data Model (EDM) 10
How is the Entity Data Model Represented? 13
The Object Model (O-Space) 15
LINQ to Entities 15
Entity Client 16
Entity SQL 16
Avoiding Complex Joins 17
The Object Services Layer 18
ADO.NET Entity Framework—Features and Benefits at a Glance 19
Installing the Prerequisites 20
Installing the ADO.NET Entity Framework and Its Tools 20
Downloading the Software 20
Installing the Software 21
Designing the Payroll Database 29
Summary 35
Glossary 35
Chapter 2: Getting Started 37
Creating an Entity Data Model 37
Creating the Payroll Entity Data Model Using the ADO.NET Entity Data
Model Designer 38
Creating the Payroll Data Model Using the EdmGen Tool 47
The ADO.NET Entity Data Source Control 51
13.
Table of Contents
[ii ]
Implementing Our First Application Using the Entity Framework 54
Summary 57
Chapter 3: Entities, Relationships, and the Entity Data Model 59
Entities, Entity Types, and Relationships in the ADO.NET Entity Data
Model (EDM) 59
What is an Entity? 60
Defining Entity Sets in the Entity Data Model 60
Extending the Existing Entity Types to Create Derived Entity Types 61
Association Sets, Associations, Containment, and Multiplicity 62
What are Entity Containers? 63
Exploring the Payroll Entity Data Model 64
The Mapping Details Window 65
The Entity Model Browser 67
The Entity Data Model Layers 68
The CSDL Schema 69
The SSDL Schema 75
The MSL Schema 80
Summary 84
Chapter 4: Working with Stored Procedures in the
Entity Data Model 85
Mapping Stored Procedures to Functions in the EDM 85
Mapping Create, Update, and Delete Functions to Entities in the EDM 89
Mapping the Association Sets Consistently 93
Mapping Stored Procedures with No Entity Set 99
Using Stored Procedures 100
Mapping Stored Procedures that Return Custom Entity Types 101
Summary 102
Chapter 5: Working with Entity Client and Entity SQL 103
An Overview of the Entity SQL Language 104
From Transact SQL (T-SQL) to Entity SQL (E-SQL) 104
Why Entity SQL When I Already have LINQ to Entities? 105
Features of Entity SQL 105
Operators in Entity SQL 106
Arithmetic Operators 106
Comparison Operators 107
Logical Operators 107
Reference Operators 108
Type Operators 108
Set Operators 108
Operator Precedence 109
Expressions in Entity SQL 109
Query Expressions in Entity SQL 109
14.
Table of Contents
[iii ]
Identifiers, Variables, Parameters, and Types in Entity SQL 110
Row 111
Collection 111
Reference 112
Canonical Functions in Entity SQL 113
Mathematical Functions 113
Aggregate Functions 113
String Functions 114
Bitwise Functions 114
Date and Time Functions 115
Data Paging Using Entity SQL 115
Working with the ADO.NET Entity Client 116
Let's Get into Action 117
Building the Connection String 117
Creating an Entity Connection 118
Opening the Connection 118
Executing Queries Using the Entity Command 119
Closing the Connection 121
Other Operations with Entity SQL 123
Inserting a Record Using Entity SQL 123
Inserting a Record with a Foreign Key Constraint 124
Retrieving Native SQL from EntityCommand 124
Transaction Management in Entity SQL 125
Summary 126
Chapter 6: Working with LINQ to Entities 127
Introducing LINQ 127
Why LINQ? 128
Understanding the LINQ Architecture 128
LINQ to XML 129
LINQ to SQL 129
LINQ to Objects 130
LINQ to Entities 131
Querying Data Using LINQ to Entities 131
LINQ to Entities and Entity Framework 131
Differences between LINQ to Entities and LINQ to SQL 132
Operators in LINQ 133
Aggregation 136
Projections 136
Ordering 137
Quantifiers 137
Restriction 138
Conversion 138
Element 139
Set 139
Querying Data Using LINQ 140
15.
Table of Contents
[iv ]
Expressions in LINQ to Entities 143
Constant Expressions 144
Comparison Expressions 144
Initializing Expressions 145
Null Comparisons 146
Navigation Properties 147
Immediate and Deferred Query Execution 148
Improving Performance with Compiled Queries 150
Summary 150
Chapter 7: Working with the Object Services Layer 151
What are Object Services? 151
Features at a Glance 153
A Quick Look at the ObjectContext Class in our Payroll EDM 153
Querying Data as in-Memory Objects 156
Adding, Modifying, and Deleting Objects 156
Attaching and Detaching Objects to and from the Object Context 158
Serializing and De-Serializing Entity Instances 159
Change Tracking and Identity Resolution Using ObjectContext 161
Implementing a Sample Application 162
Creating the Form 162
Implementing a Custom DataContext 164
How is This Accomplished? 167
Inheritance in the Entity Framework 176
Table per Hierarchy 176
Table per Type 177
Implementing Complex Types in the EDM 180
Summary 181
Chapter 8: Introducing ADO.NET Data Services 183
Introducing ADO.NET Data Services 184
How Do ADO.NET Data Services and Web Services Differ? 184
What is Representational State Transfer (REST)? 184
Why Use ADO.NET Data Services? 185
Features at a Glance 185
Prerequisites 186
Exposing Data as a Service Using ADO.NET Data Services 186
Creating an ADO.NET Data Service 187
Using a Relational Database as the Data Source 189
Using Data Sources Other Than a Relational Database 192
Understanding the System.Services.Data Namespace 194
Restricting Access to Resources 196
Working with the ADO.NET Data Service Client Library 197
Generating the Client-Side Entity Classes 198
16.
Table of Contents
[v ]
Inserting a Record 198
Updating a Record 199
Deleting a Record 200
Consuming an ADO.NET Data Service Using LINQ 201
Exposing a Stored Procedure as a URI 201
Handling Exceptions in ADO.NET Data Services 202
Batching ADO.NET Data Services Requests to Improve Performance 204
Debugging Your Data Service 204
References 205
Summary 206
Index 207
18.
Preface
The ADO.NET EntityFramework, the next generation of Microsoft's data access
technology, is an extended Object Relational Mapping (ORM) technology that makes
it easy to tie together the data in your database with the objects in your applications.
This is done by abstracting the object model of an application from its relational or
logical model. It is an extended ORM in the sense that it provides many additional
features over an ORM. Some of these features are:
Entity Inheritance and Composition
Identity Resolution and Change Tracking
LINQ Support
The Object Service Layer
This book is a clear and concise guide to the ADO.NET Entity Framework. Packed
with plentiful code examples, this book helps you to learn the ADO.NET Entity
Framework and ADO.NET Data Services and build a better data access layer for
your application.
What This Book Covers
Chapter 1 is an introduction to the basics of the ADO.NET Entity Framework (EF), its
usefulness, its features, and the benefits.
Chapter 2 discusses how you can get started with EF, create an Entity Data Model
(EDM), and write a program to query data.
Chapter 3 gives a detailed explanation of entities, relationships, and each of the
sections of the EDM.
Chapter 4 provides a sample application that illustrates how to perform CRUD
operations against the EDM.
•
•
•
•
19.
Preface
[ 2 ]
Chapter5 discusses the Entity SQL query language and how to work with the Entity
Client provider.
Chapter 6 includes a detailed discussion on LINQ to Entities with many
code examples.
Chapter 7 provides a detailed discussion on the Object Services Layer and its
helpful and useful features.
Chapter 8 provides an introduction to ADO.NET Data Services and how it can be
used with the EDM to perform CRUD operations.
What You Need for This Book
To learn the concepts covered in this book, the reader should have a proper
understanding and working knowledge of the following:
ADO.NET
ASP.NET
C#
To execute the code samples in this book, the following technologies should be
installed in your system:
Visual Studio 2008
Visual Studio 2008 SP1
SQL Server 2005
Windows XP/Vista/2003 or higher
Who This Book is For
This book is for C# developers who want an easier way to create their data access
layer. You will need to be comfortable with ADO.NET, but you do not need to know
anything about the Entity Framework. Along the way we will create some ASP.NET
applications, so familiarity with this will be helpful.
•
•
•
•
•
•
•
20.
Preface
[ 3 ]
Conventions
Inthis book, you will find various styles of text that help distinguish between
different kinds of information. Let's look at some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows:
"We can include other contexts through the use of the include directive."
A block of code will be set as follows:
<asp:BoundField DataField="FirstName" HeaderText="First
Name" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last
Name" SortExpression="LastName" />
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items will be made bold. Note that last two lines of the following
code sample:
<FunctionImport Name="DeleteEmployee">
<Parameter Name="EmployeeID" Mode="In" Type="Int32" />
<Parameter Name="DepartmentID" Mode="In" Type="Int32" />
<Parameter Name="DesignationID" Mode="In" Type="Int32" />
Any command-line input and output will be written as follows:
edmgen /mode:fullgeneration /c:"Data Source=.;Initial
Catalog=Payroll;User ID=sa;Password=joydip1@3;" /p:Payroll
New terms and important words are introduced in a bold-type font. Words that you
see on the screen, in menus or dialog boxes for example, appear in our text like this:
"clicking the Next button moves you to the next screen".
Important notes appear in a box like this with the
Notes icon on the left..
Tips and tricks appear like this with the Tips icon
on the left.
21.
Preface
[ 4 ]
ReaderFeedback
Feedback from our readers is always welcome. Let us know what you think about
this book, what you liked or may have disliked. Reader feedback is important for us
to develop titles that you really get the most out of.
To send us general feedback, simply drop an email to feedback@packtpub.com,
making sure to mention the book title in the subject line of your message.
If there is a book that you need and would like to see us publish, please send
us a note in the SUGGEST A TITLE form on www.packtpub.com or email
suggest@packtpub.com.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer Support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Downloading the Example Code for the Book
Visit http://www.packtpub.com/files/code/5227_Code.zip to directly
download the example code.
The downloadable files contain instructions on how to use them.
Errors
Although we have taken every care to ensure the accuracy of our contents, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in text or
code—we would be grateful if you would report this to us. By doing this you can
save other readers from frustration, and help to improve subsequent versions of
this book. If you find any errors, report them by visiting http://www.packtpub.
com/support, selecting your book, clicking on the let us know link, and entering
the details of your errors. Once your errors are verified, your submission will be
accepted and the errata added to the list of existing errors. The existing errors can be
viewed by selecting your title from http://www.packtpub.com/support.
22.
Preface
[ 5 ]
Piracy
Piracyof copyright material on the Internet is an ongoing problem across all media. At
Packt, we take the protection of our copyright and licenses very seriously. If you come
across any illegal copies of our works in any form on the Internet, please provide the
location address or website name immediately so we can pursue a remedy.
Please contact us at copyright@packtpub.com with a link to the suspected
pirated material.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you have a problem or
question with some aspect of this book. We will do our best to address these
questions and problems.
24.
Introducing the ADO.NET
EntityFramework
The ADO.NET Entity Framework is an extended Object Relational Mapping (ORM)
technology from Microsoft that abstracts the object model of an application from its
relational or logical model. That is, it isolates the object model from the way the data
is actually represented in the relational store. This framework makes the conceptual
model real by using an extended entity relationship model called the ADO.NET
Entity Data Model.
This chapter gives you an introduction to the ADO.NET Entity Framework and also
equips you with a brief understanding of the related terminologies. We will
revisit each of the Entity Framework architectural components as we progress
through this book. Our journey of the ADO.NET Entity Framework has just begun!
In this chapter, we will cover the following points:
An overview of the ADO.NET Entity Framework
The ADO.NET Entity Framework Architectural Components
Features and benefits of the ADO.NET Entity Framework
Installing the ADO.NET Entity Framework
But, before we delve deep into this amazing technology from Microsoft, let's take a
quick look at the prerequisites for learning the concepts covered in this book.
•
•
•
•
25.
Introducing the ADO.NETEntity Framework
[ 8 ]
What You should Know
To learn the concepts covered in this book, the reader should have a basic
understanding of the following:
Programming using ADO.NET
C#
Working with ASP.NET Web Applications
SQL Server
Looking Back
Any application has two perspectives. They are the Data Model and the Object
Model. While the Data Model defines the way the data is defined and stored,
the Object Model defines how the same data will be represented to the user in
the presentation layer or, is exposed to the other layers of the application. The
Data Model of the application usually deals with the storage and retrieval of the
application's data to and from the relational store.
The relational store is used for data persistence, consistency, concurrency, and
security. It contains the application's data and typically comprises of a set of tables,
views, functions, procedures, and the relationships. You typically use T-SQL to
query against the relational store which returns result sets that contains columns and
rows of data.
However, the data returned doesn't necessarily match with the application's object
oriented programming model. Usually, we don't use the data returned in the same
form in which it is returned from the relational store. We write the necessary code to
transform the data returned from the relational store to business objects in the data
access layer of the application. Similarly, you need into write code to transform your
application's business objects into a form that can be persisted into your relational
store. But, what if the schema of the underlying relational store changes?
To bridge this apparent mismatch between the data and the object models, ORM
tools have evolved. They are used to reduce the code required to transform your
application's business objects into a form that can be persisted into the relational
store and vice-versa.
•
•
•
•
26.
Chapter 1
[ 9]
What is ADO.NET Entity Framework?
The ADO.NET Entity Framework is a type of ORM. It is a development platform that
provides a layer of abstraction on top of the relational or logical model. In doing so, it
isolates the object model of the application from the way the data is actually stored in
the relational store. Developers can use the ADO.NET Entity Framework to program
against an object model rather than the logical or relationship model.
This level of abstraction is achieved using the Entity Data Model (EDM)—an
extended Entity Relationship Model. The EDM reduces the dependency of your
domain object model on the database schema of the data store in use. We will discuss
more on this topic later in this chapter.
Developers can use the ADO.NET Entity Framework to work with domain specific
properties such as employee name employee address, contact details, etc, without
having to be concerned with how the actual data is stored and represented in the
underlying data store. The framework can take care of the necessary translations to
either retrieve data from your data store, or, perform inserts, updates, and deletes.
Is It Just Another ORM?
The ADO.NET Entity Framework is an extended ORM technology from Microsoft.
We say it is an extended ORM because it has many additional features compared
to a typical ORM. ORMs often use metadata and factory classes to retrieve data or
collections of data. On the contrary, using the Entity Framework, you can easily map
your data to be accessible in a relational representation in the database to objects,
no matter how the mapping is implemented. You can expose different data views to
your application without having to change your relational schema. In essence, this
allows the applications to have their own view of the data. The applications can even
reuse the same views of data amongst themselves.
The major difference between the ADO.NET Entity Framework and ORM tools is in
the Entity Data Model and the former's ability to query data using strongly typed
LINQ. You can even use Entity SQL, a T-SQL like query language for querying the
Entity Data Model, to execute dynamic queries. In addition to what a typical ORM
framework provides, the ADO.NET Entity Framework provides and supports entity
inheritance, entity composition, and a flexible, loosely coupled three tiered model
consisting of the conceptual model, the mapping layer, and the storage model.
The ADO.NET Entity Framework enables you to even extend the existing schema. In
other words, you can extend the generated entity classes to create your own custom
entity classes. You can define relationships of any kind such as one-to-one,
one-to-many, and even many-to-many. So, isn't it a better ORM?
27.
Introducing the ADO.NETEntity Framework
[ 10 ]
The ADO.NET Entity Framework
Architectural Components
The ADO.NET Entity Framework is comprised of the following components:
The Entity Data Model
LINQ to Entities
Entity Client
Entity SQL
The Object Services Layer
The following figure illustrates the layers of the ADO.NET Entity Framework and
how they are related to each other:
LINQ to
Entities
Object Services
Object Query
Entity SQL
Entity SQL
The Conceptual Model Layer (Defined using .CSDL files)
The Mapping Layer (Defined using .MSDL files)
The Logical Model Layer (Defined using .SSDL files)
Database
We will now discuss each of the components of the Entity Framework technology
stack in the following sections.
The Entity Data Model (EDM)
The Entity Data Model, an extended entity relationship model, is the core of the
ADO.NET Entity Framework.
You can generate an Entity Data Model using the EDMGen.exe command line tool,
or, using the ADO.NET Entity Data Model designer—a new Visual Studio template.
We will discuss how an Entity Data Model can be generated from a relational
schema in the next chapter.
•
•
•
•
•
28.
Chapter 1
[ 11]
The following figure illustrates where exactly the Entity Data Model fits in:
.NET Objects or collection of
.NET Objects
The ADO.NET Entity Data Model
The Relational Data Store
The Entity Data Model abstracts the logical or the relational schema and exposes the
conceptual schema of the data using a three-layered approach. It is comprised of the
following layers:
The Conceptual Data Definition Language Layer (C-Space)
The Mapping Schema Definition Language Layer (C-S Space)
The Store Space Definition Language Layer (S-Space)
The following figure illustrates the layers of the Entity Data Model:
The ADO.NET Entity Data Model Layers
The Conceptual or the C-Space (GSDL)
Comprises of EntityContainer, EntitySets, AssociationSets, Association Types,
EntityTypes, Relationships and Functions
Queried using Entity SQL or ESQL (EntityConnection, EntityCommand, EntityDataReader)
The Mapping Layer or the C-S Mapping Layer (MSL)
The Logical or the S-Space (SSDL)
Comprises of Tables, Stored Procedures, Views and Functions
Queried using ADO.NET Data Providers
(SQLConnection, SQLCommand, SQLDataReader, SQLDataAdapter, etc using T-SQL
or, using PL-SQL)
•
•
•
29.
Introducing the ADO.NETEntity Framework
[ 12 ]
The Conceptual Layer or the C-Space Layer is responsible for defining the entities
and their relationships. It defines your business objects and their relationships in
XML files. The C-Space is modeled using CSDL and is comprised of EntityContainer,
EntitySets, AssociationSets, AssociationTypes, EntityTypes, and Functions. You can
query this layer using Entity SQL or ESQL (EntityConnection, EntityCommand, and
EntityDataReader).
The C-S Mapping Layer is responsible for mapping the conceptual and the logical
layers. That is, it maps the business objects and the relationships defined in the
conceptual layer with the tables and relationships defined in the logical layer. It is
a mapping system created in XML, which links or maps the Conceptual and the
Logical layers. The C-S Mapping layer is modeled using MSL.
The Logical or the Storage Layer (also called the S-Space) represents the schema
of the underlying database. This is comprised of tables, stored procedures, view,
and functions. It is modeled using SSDL and queried using ADO.NET Data
Providers. Hence, we use SQLConnection, SQLCommand, SQLDataReader, and
SQLDataAdapter using T-SQL or PL-SQL if our data store is a SQL database.
Here is how a typical Entity Data Model looks:
30.
Chapter 1
[ 13]
How is the Entity Data Model Represented?
The Entity Data Model uses the following three types of XML files to represent the
C-Space, C-S Space, and the S-Space respectively.
.CSDL (Conceptual Schema Definition Language): This represents the C-S
Space and is used to map the entity types used in the conceptual model.
.MSL (Mapping Schema Language): This represents the C-S Space and is
used to map the logical model to the conceptual model.
.SSDL (Store Schema Definition Language): This represents the S-Space and
is used to map the schema information of the logical layer.
If you use the ADO.NET Entity Data Model Designer tool to generate
your Entity Data Model, you will have one .edmx file that contains
the CSDL, MSL, and SSDL sections bundled into one single file. At
runtime, the .csdl, .msl, and .ssdl files are created in the application's
output directory.
These files store the metadata information as XML for each of the above layers. Here
is what the CSDL section of your Entity Data Model looks like:
<!-- CSDL content -->
<edmx:ConceptualModels>
<EntityContainer Name="PayrollEntities">
<EntitySet Name="Designation" EntityType="PayrollModel.
Designation" />
</EntityContainer>
<EntityType Name="Designation">
<Key>
<PropertyRef Name="DesignationID" />
</Key>
<Property Name="DesignationID" Type="Int32" Nullable=
"false" />
<Property Name="DesignationName" Type="String"
Nullable="false" MaxLength="50" Unicode="false" />
<NavigationProperty Name="Employee" Relationship=
"PayrollModel.FK_Employee_Designation" FromRole="Designation"
ToRole="Employee" />
</EntityType>
</edmx:ConceptualModels>
•
•
•
31.
Introducing the ADO.NETEntity Framework
[ 14 ]
Here is how a typical SSDL section of the Entity Data Model looks like:
<!-- SSDL content -->
<edmx:StorageModels>
<EntityContainer Name="dbo">
<EntitySet Name="Designation" EntityType=
"PayrollModel.Store.Designation" />
</EntityContainer>
<EntityType Name="Designation">
<Key>
<PropertyRef Name="DesignationID" />
</Key>
<Property Name="DesignationID" Type="int" Nullable="false"
StoreGeneratedPattern="Identity" />
<Property Name="DesignationName" Type="varchar"
Nullable="false" MaxLength="50" />
</EntityType>
</Schema>
</edmx:StorageModels>
And here is the C-S maping section for you:
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:
storage:mapping:CS">
<EntityContainerMapping StorageEntityContainer="dbo"
CdmEntityContainer="PayrollEntities">
<EntitySetMapping Name="Designation">
<EntityTypeMapping TypeName="IsTypeOf(PayrollModel.
Designation)">
<MappingFragment StoreEntitySet="Designation">
<ScalarProperty Name="DesignationID" ColumnName=
"DesignationID" />
<ScalarProperty Name="DesignationName" ColumnName=
"DesignationName" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
</edmx:Edmx>
32.
Chapter 1
[ 15]
You can also create abstract and complex types in your Entity Data
Model. You can derive from an abstract type to create sub-types, but no
instance of the abstract type can be created. You can also create complex
types. That is, types that don't have any identity of their own. A typical
example of a complex type is the Address type.
We will skip further discussion on each of the sections of an Entity Data Model
until Chapter 3.
The Object Model (O-Space)
When working with the ADO.NET Entity Framework, you will have an
Object Model on top of all the Entity Data Model layers. You need to model the
Object Model using .NET objects. The following figure illustrates how the Object
Model fits in with the EDM layers:
The Object Model or the O-Space
The O-C Mapping Layer
The Conceptual Model or the C-Space (Modelled using CSDL)
The Mapping Layer or the C-S Space (Modelled using MSL)
The Logical Model or the S-Space (Modelled using SSDL)
The Object Model Layer contains, .NET objects, collection of .NET objects, types,
properties and methods. You can use the Object Model or the O-Space Model to
query your business objects, or the collections of your business objects, using LINQ
to Entities or Entity SQL. The C-Space and O-Space models are actually mapped by
the O-C Mapping Layer using code attributes applied to the O-space Model.
LINQ to Entities
Language Integrated Query (LINQ) is a query translation pipeline that has been
introduced as part of the C# 3.0 library. It comprises a set of query operators for
different data sources (LDAP, Objects, CSV, XML, Entities, SQL, etc.). It is an
extension of the C# language and provides a simplified framework for accessing
relational data in a strongly typed, Object Oriented manner.
33.
Introducing the ADO.NETEntity Framework
[ 16 ]
LINQ to Entities is a Microsoft technology that enables you to query your business
objects from within the language in a strongly typed manner. You can use LINQ to
Entities, a superset of LINQ to SQL, to query data against a conceptual data model,
namely, the Entity Data Model. We will learn more on LINQ and LINQ to Entities in
the chapter 6.
Here is an example of a typical LINQ to Entities query:
PayrollModel.PayrollEntities ctx = new PayrollModel.PayrollEntities();
var query = from emp in ctx.Employee
select emp;
foreach (var employee in query)
Response.Write("<BR>"+employee.FirstName);
LINQ to Entities rests on top of the ADO.NET Entity Framework's
Object Services Layer and that the LINQ to Entities queries are internally
translated to canonical query trees. This, in turn, gets converted internally
to corresponding SQL queries in a form expected by your underlying
database.
Entity Client
Entity Client, the gateway to entity-level queries, is the Entity Framework's
counterpart of ADO.NET's SQL Client or Oracle Client that uses Entity SQL
or E-SQL to query the conceptual model. You create a connection using Entity
Connection, execute commands through Entity Commands, and retrieve the result
sets as Entity Data Readers.
Entity SQL
Entity SQL is a data store independent derivative of T-SQL that supports entity
inheritance and relationships. You can use it to query data using the conceptual
schema. You can even build your own dynamic queries. These E-SQL queries are
internally translated to data store dependent SQL queries. This translation, that
is, the conversion of the E-SQL queries to their data store-specific query language
like T-SQL, (it doesn't need to be only T-SQL, however, it is the supported one) is
handled by the Entity Framework. Entity SQL or E-SQL may not be as strongly
typed as LINQ is, but, you have the flexibility of executing dynamic queries using it,
much like T-SQL.
34.
Chapter 1
[ 17]
Strongly typed data access is one of the most striking features of LINQ.
LINQ queries are checked at compile time. This is unlike SQL queries
which are only detected at runtime.
But, why do you need Entity SQL when you have LINQ to Entities to query data
through you Entity Data Model? You can, using Entity SQL, compose queries that
are difficult to determine until the time the query is executed. On a different note,
Entity SQL is a full text-based query language that you can use in much the same
way as you use ADO.NET data providers.
Here is an example that shows how you can use Entity SQL to insert data in
your applications.
using (EntityConnection conn = new EntityConnection("Name=PayrollEnti
ties"))
{
try
{
conn.Open();
EntityCommand cmd = conn.CreateCommand();
cmd.CommandText = "PayrollEntities.AddNewEmployee";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("FirstName", "Joydip");
cmd.Parameters.AddWithValue("LastName", "Kanjilal");
cmd.Parameters.AddWithValue("Address", "Hyderabad");
cmd.Parameters.AddWithValue("DepartmentID", 4);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
To query data from the Entity Data Model, you have three
choices—Entity SQL, LINQ to Entities, and Object Services.
Avoiding Complex Joins
You can use Entity SQL to avoid complex joins as you will typically be querying
against a conceptual model of the data. As an example, if we want to display employee
names and the department names in which they work, we would have to join the
information of the Employee and the Department tables and then filter the unwanted
columns to retrieve only the information that is required. Such traversals become a
nightmare as you add additional tables and you therefore require more complex joins.
35.
Introducing the ADO.NETEntity Framework
[ 18 ]
When you implement your Object Model using Object Oriented Programming
Languages, you expose the object's relationships with other objects of its kind using
properties. This is in contrast to the approach we just discussed. Hence, designing
an Object Model using this approach is cumbersome. This is exactly where the ADO.
NET Entity Framework fits in; it represents the conceptual and logical model of data
while using grammar that is common to both.
Here is a code snippet that explains how you can use Entity SQL to avoid complex
joins in your application's code. The following T-SQL query can be used to retrieve
employee data split across three tables, namely, Employee, Department, and Salary.
Select Employee.FirstName, Employee.LastName, Department.
DepartmentName, Salary.Basic
from Employee
INNER JOIN
Department on Department.DepartmentID = Employee.DepartmentID
INNER JOIN
Salary on Salary.EmployeeID = Employee.EmployeeID
And, here is how you will use the Entity SQL to achieve the same result:
Select FirstName, LastName, DepartmentName, Basic from EmployeeData
The Object Services Layer
Apart from querying the Conceptual Model, you might, at some point, have to work
with entities such as in-memory objects or a collection of in-memory objects. To do
this you need Object Services. You can use it to query data, from almost any data
store, with less code. In addition to from enabling you to perform CRUD operations,
the Object Services Layer provides the following additional services:
Change tracking
Lazy loading
Inheritance
Optimistic concurrency
Merging data
Identity resolution
Support for querying data using Entity SQL and LINQ to Entities
We will learn more about Object Services later in the book. The Object Services Layer
internally uses an Object Query object for query processing. Note that the Object
Services Layer supports querying data using both Entity SQL and LINQ to Entities.
•
•
•
•
•
•
•
36.
Chapter 1
[ 19]
You can query data from the Entity Data Model either using Object
Services or Entity Client. However, if you require change tracking, be
aware that only Object Services provides this feature. Note that in either
case, the ADO.NET Data Providers are responsible for talking to the
underlying database.
Here is an example that shows how you can use Object Services to retrieve data.
using (ObjectContext ctx = new ObjectContext("Name=PayrollEntities"))
{
var query = from employee in ctx.CreateQuery<PayrollModel.
Employee>("PayrollEntities.
Employee") select employee;
foreach (PayrollModel.Employee emp in query)
{
Response.Write("<BR>" + emp.FirstName);
}
}
ADO.NET Entity Framework—Features and
Benefits at a Glance
Here is a quick look at some of the features and benefits of the ADO.NET
Entity Framework:
Increased level of abstraction.
An extensible and flexible provider model.
Seamless querying of data using Entity SQL and LINQ.
A flexible schema for storing the mapping information.
Reduction to the amount of KLOC needed to write data access code in your
applications.
Provides a layer of abstraction on top of any data store as long as an
implementation for the underlying data store is provided.
A powerful Object Services Layer.
A full text-based query language.
Support for a conceptual data model of an application.
•
•
•
•
•
•
•
•
•
37.
Introducing the ADO.NETEntity Framework
[ 20 ]
KLOC refers to Kilo Lines of Code, a unit of measuring the amount of
source code in your programs.
Installing the Prerequisites
To run the programs given in this book, you should have the following elements
installed on your system:
Visual Studio.NET 2008 Professional
SQL Server 2005 or higher
Microsoft .NET Framework 3.5 SP1
ADO.NET Entity Framework Beta 3 or higher
ADO.NET Entity Framework Tools December 2007 CTP or higher
Installing the ADO.NET Entity Framework and
Its Tools
Before you proceed with installing EF Beta 3 and its tools, make sure that you have
installed Visual Studio.NET 2008 Professional and SQL Server 2005 on your system.
I will skip the discussion on installing Visual Studio 2008 Professional and SQL
Server 2005 at this time.
Downloading the Software
Let us take a look at the necessary software that you need to download in order to
work with the ADO.NET Entity Framework.
Download ADO.NET Entity Framework Beta 3 from the following link:
http://www.microsoft.com/downloads/details.
aspx?FamilyId=15DB9989-1621-444D-9B18-D1A04A21B519&displaylang
=en
Download ADO.NET Entity Framework Tools December 2007 CTP from the
link give below:
http://www.microsoft.com/downloads/details.
aspx?FamilyId=D8AE4404-8E05-41FC-94C8-C73D9E238F82&displaylang
=en
•
•
•
•
•
•
•
38.
Chapter 1
[ 21]
Download the patch update to Visual Studio.NET 2008 from the link
given below:
http://go.microsoft.com/fwlink/?LinkID=104985
Download Microsoft .NET Framework 3.5 SP1 from the following link:
http://www.microsoft.com/downloads/details.
aspx?FamilyId=8C36ACA4-E947-4760-9B05-93CAC04C6F87&displaylang
=en
Installing the Software
Now that the required software has been downloaded, we will now install each
one individually.
Double-click on the ADO.NET Entity Framework Setup file. The following
installation wizard window will appear:
Now, click on Next.
•
•
39.
Introducing the ADO.NETEntity Framework
[ 22 ]
Here is how the next screen looks like:
In the above window that appears, check the checkbox and click on Install.
The installation procedure starts and when done, the following screen appears:
40.
Chapter 1
[ 23]
Click on Finish to complete the installation process.
Now that you have installed the ADO.NET Entity Framework successfully on your
system, the next step is to install the ADO.NET Entity Framework Tools CTP. But
before you do that, you need to install the Visual Studio.NET 2008 patch update.
Double-click on the Visual Studio.NET patch update setup file that you downloaded
earlier. The following window appears:
Now, click on Next.
41.
Introducing the ADO.NETEntity Framework
[ 24 ]
The following window appears:
Check the check box to agree and accept the license terms and click on Next to start
the installation process.
Once the installation is complete, the following window appears:
42.
Chapter 1
[ 25]
Click on Finish to complete the installation process.
Now, we need to install the ADO.NET Entity Framework Tools CTP. To do this,
double-click on the ADO.NET Entity Framework December 2007 Tools CTP you
downloaded earlier. The following screen appears:
43.
Introducing the ADO.NETEntity Framework
[ 26 ]
Click on Next. The following window appears:
Now, check the check box to accept the license terms and click on Next. The
following window will appear:
44.
Chapter 1
[ 27]
Click on Install to start the installation process. Once the installation is complete, the
following window is displayed:
Clink on Finish to complete the installation process.
We will now install Microsoft .NET Framework 3.5 SP1. It contains many additional
features and most importantly, we need it to work with the Entity Data Source
control. We will discuss this control in the next chapter.
45.
Introducing the ADO.NETEntity Framework
[ 28 ]
To install Microsoft .NET Framework 3.5 SP1 on your system, double-click on the
setup file you downloaded earlier. The following screenshot shows the window that
will appear:
Select the radio button to accept the terms of the license agreement and click on
Install to start the installation process.
46.
Chapter 1
[ 29]
Once the installation process is complete, the following window is displayed:
Click on Exit to complete the installation process. You are done!
Having installed these prerequisites, we will now design our sample database. We
will use this database throughout this book. We will assign the name Payroll to our
design database. The next section discusses the design of this sample database.
Designing the Payroll Database
In this section, we will design our Payroll database, which we will use throughout
this book. This database will comprised of the following five tables:
Employee
Department
Designation
Salary
Provident Fund
•
•
•
•
•
47.
Introducing the ADO.NETEntity Framework
[ 30 ]
Here is the script for creating these tables.
CREATE TABLE [dbo].[Employee](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[Address] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[Phone] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[DepartmentID] [int] NOT NULL,
[JoiningDate] [datetime] NOT NULL,
[LeavingDate] [datetime] NULL,
[DesignationID] [int] NOT NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Department](
[DepartmentID] [bigint] NOT NULL,
[DepartmentName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL,
[DepartmentHead] [bigint] NOT NULL,
CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED
(
[DepartmentID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Designation](
[DesignationID] [bigint] NOT NULL,
[DesignationName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_
AS NOT NULL,
CONSTRAINT [PK_Designation] PRIMARY KEY CLUSTERED
(
[DesignationID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Salary](
[SalaryID] [bigint] NOT NULL,
[EmployeeID] [bigint] NOT NULL,
[Basic] [money] NOT NULL,
[Allowance] [money] NOT NULL,
[PFID] [bigint] NULL,
[Tax] [money] NOT NULL,
[GrossSalary] [money] NOT NULL,
48.
Chapter 1
[ 31]
[NetSalary] [money] NOT NULL,
CONSTRAINT [PK_Salary] PRIMARY KEY CLUSTERED
(
[SalaryID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[ProvidentFund](
[PFID] [bigint] NOT NULL,
[PFAmount] [money] NOT NULL,
CONSTRAINT [PK_ProvidentFund] PRIMARY KEY CLUSTERED
(
[PFID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Here is how the database diagram for our Payroll database looks:
49.
Introducing the ADO.NETEntity Framework
[ 32 ]
We will create some stored procedures now that we will use to insert, update, and
delete data from the tables we just created. Here is a list of the stored procedures that
we will create for our Payroll database:
Employee_Insert
Employee_Update
Employee_Delete
Department_Insert
Department_Update
Department_Delete
Designation_Insert
Designation_Update
Designation_Delete
ProvidentFund_Insert
ProvidentFund_Update
ProvidentFund_Delete
Salary_Insert
Salary_Update
Salary_Delete
Here is the script for these procedures.
Create Procedure Employee_Insert
As
@FirstName varchar(50), @LastName varchar(50), @Address varchar(50),
@Phone varchar(50), @DepartmentID int, @DesignationID int,
@JoiningDate datetime, @LeavingDate datetime
as
Insert into Employee(DepartmentID, DesignationID, JoiningDate,
LeavingDate) values (@DepartmentID, @DesignationID, @JoiningDate,
@LeavingDate)
Go
Create Procedure Employee_Update
@EmployeeID int, @FirstName varchar(50), @LastName varchar(50),
@Address varchar(50), @Phone varchar(50), @DepartmentID int,
@DesignationID int
as
Update Employee Set DepartmentID = @DepartmentID, DesignationID =
@DesignationID Where Employee.EmployeeID = @EmployeeID
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
50.
Chapter 1
[ 33]
Go
Create Procedure Employee_Delete
@EmployeeID int
as
Delete from Employee where Employee.EmployeeID = @EmployeeID
Go
Create Procedure Department_Insert
@DepartmentName varchar(50)
as
Insert into Department (DepartmentName) values (@DepartmentName)
Go
Create Procedure Department_Update
@DepartmentID int,@DepartmentName varchar(50)
as
Update Department Set DepartmentName = @DepartmentName where
DepartmentID = @DepartmentID
Go
Create Procedure Department_Delete
@DepartmentID int
as
Delete from Department where DepartmentID = @DepartmentID
Go
Create Procedure Designation_Insert
@DesignationName varchar(50)
as
Insert into Designation (DesignationName) values (@DesignationName)
Go
Create Procedure Designation_Update
@DesignationID int, @DesignationName varchar(50)
as
Update Designation Set DesignationName = @DesignationName where
DesignationID=@DesignationID
Go
Create Procedure Designation_Delete
@DesignationID int
as
Delete from Designation where DesignationID=@DesignationID
Go
Create Procedure ProvidentFund_Insert
@EmployeeID int, @PFAmount money
as
Insert into ProvidentFund (EmployeeID, PFAmount) values (@EmployeeID,
@PFAmount)
51.
Introducing the ADO.NETEntity Framework
[ 34 ]
Go
Create Procedure ProvidentFund_Update
@PFID int, @EmployeeID int, @PFAmount money
as
Update ProvidentFund set EmployeeID = @EmployeeID, PFAmount =
@PFAmount where PFID = @PFID
Go
Create Procedure ProvidentFund_Delete
@PFID int
as
Delete from ProvidentFund where PFID = @PFID
Go
Create Procedure Salary_Insert
@EmployeeID int, @PFID int, @Basic money, @Allowance money,
@Tax money, @GrossSalary money, @NetSalary money
as
Insert into Salary(EmployeeID, PFID, Basic, Allowance, Tax,
GrossSalary, NetSalary) values (@EmployeeID, @PFID, @Basic,
@Allowance, @Tax, @GrossSalary, @NetSalary)
Go
Create Procedure Salary_Update
@SalaryID int, @EmployeeID int, @PFID int, @Basic money, @Allowance
money, @Tax money, @GrossSalary money, @NetSalary money
as
Update Salary set EmployeeID = @EmployeeID, PFID = @PFID, Basic =
@Basic, Allowance = @Allowance, Tax = @Tax, GrossSalary = @
GrossSalary, NetSalary = @NetSalary where SalaryID = @SalaryID
Go
Create Procedure Salary_Delete
@SalaryID int
as
Delete from Salary where SalaryID = @SalaryID
We will add more tables and stored procedures to our Payroll database as necessary
in the chapters to follow.
52.
Chapter 1
[ 35]
Summary
The ADO.NET Entity Framework mainly addressees how easily you can persist and
query your data with many of added services. You can use the ADO.NET Entity
Framework to focus on the object model rather than the logical model. In other
words, you can add a level of abstraction on top of your relational store.
In this chapter, we have had a look at what this framework is, its architecture,
advantages, and how it differs from LINQ to SQL (formerly called DLINQ). In the
next chapter, we will learn how to get started with the ADO.NET Entity Framework.
Glossary
Entity: This is the core concept in the Entity Framework. An Entity essentially
models individual objects, like, employees, customers, etc. It is something that is
uniquely definable, distinctly identifiable, and contains information pertaining to
the entity.
Relational or Logical Model: A relational or logical model depicts the logical view
of data that comprises of the normalized entities and their inter-relationships in
a database.
Object Model: An Object Model may be defined as a collection of the objects,
members, and properties of a class and the relationships between them that
illustrates the structure of a system. An Object Model of a system is centered on the
three basic properties of Object Oriented Programming—encapsulation, abstraction,
and inheritance.
The Entity Data Model (EDM) is an implementation for the Entity – Relationship
model (commonly called the E-R model). It depicts the entities and their
relationships. The EDM is a view of the data store that your application will use.
54.
Getting Started
In theprevious chapter we took a look at the ADO.NET Entity Framework including
its architecture and its features. We also designed our Payroll database that we
will be using throughout this book to store and retrieve data. We will use the same
database in this chapter to generate an Entity Data Model and then use it, along with
the Entity Data Source control, to bind data to a GridView data control.
In this chapter, we will cover the following points:
Creating an Entity Data Model
Introducing the Entity Data Source Control
Implementing our first application using the ADO.NET Entity Framework
We will start this chapter with a discussion on how we can create an Entity Data
Model from our Payroll database.
Creating an Entity Data Model
You can create the ADO.NET Entity Data Model in one of two ways:
Use the ADO.NET Entity Data Model Designer
Use the command line Entity Data Model Designer called EdmGen.exe
We will first take a look at how we can design an Entity Data Model using the ADO.
NET Entity Data Model Designer which is a Visual Studio wizard that is enabled
after you install ADO.NET Entity Framework and its tools. It provides a graphical
interface that you can use to generate an Entity Data Model.
•
•
•
•
•
about his family,anything along this line and I don't think I ever
discussed my past with him.
Mr. Jenner. Was any mention ever made of his attendance at or
even the name of the Albert Schweitzer College?
Mr. Thornley. No.
Mr. Jenner. No discussions about any plans of his or possibility of
his seeking further education of any kind or character when he was
mustered out of the Marines?
Mr. Thornley. None whatsoever. For one thing we were not close
enough friends to have any personal interests in each other. I looked
upon him as somebody to argue with, another atheist—therefore,
without the problem of religion between us—and to argue
philosophy and politics about, and I think he looked upon me in
about the same light.
Mr. Jenner. What was your dexterity with Marine weapons?
Mr. Thornley. Mine?
Mr. Jenner. Yes.
Mr. Thornley. I was a sharpshooter.
Mr. Jenner. What was his?
Mr. Thornley. I believe—well, at that time I didn't know.
Mr. Jenner. You didn't know. I want your viewpoint as of that
time. While you were based at El Toro, did the unit engage with any
regularity in rifle practice?
Mr. Thornley. None whatsoever. At that time, the whole time I
was there, we did not engage in rifle practice.
Mr. Jenner. As a matter of curiosity on my own part, why was
that?
Mr. Thornley. Well, in the Marine Corps you are required once a
year to go to the rifle range and qualify. I was not there an entire
year. Point No. 2, this was the Marine air wing which has much less
57.
of an emphasison, in general, on rifle practice because it is not
going to be utilized in battle, and a much stronger emphasis, in the
case of the outfit we were in, on our particular military occupational
specialty.
Mr. Jenner. Which was?
Mr. Thornley. 6749 Aviation Electronic Operator.
Mr. Jenner. Was this true when you reached Japan?
Mr. Thornley. More so. When I reached Japan, however, we did
go to the rifle range one time shortly after I got there, and qualify. I
recall at that time that in Japan we weren't even having rifle
inspections. There you could put your rifle away in your locker and
forget about it, and take it out every couple of months and make
sure it hadn't corroded away, and put it back again.
Mr. Jenner. But you didn't even have rifle inspection?
Mr. Thornley. Once in a while we would have one, but not with
any frequency whatsoever.
Mr. Jenner. Were you forewarned so that you could clean your
rifle?
Mr. Thornley. No; usually you were caught unawares, which was
why you kept it clean in the locker.
Mr. Jenner. I see. What are the grades of marksmanship?
Mr. Thornley. Marksman, sharpshooter, and expert.
Mr. Jenner. Marksman, sharpshooter, and expert. Therefore, I
gather from that that marksman was the basic grade.
Mr. Thornley. Yes.
Mr. Jenner. A grade that every marine was expected to, and had
to, attain that grade?
Mr. Thornley. Not had to attain, some didn't, and there was no
particular penalty involved, except maybe something a little
extracurricular when you were in boot camp. Otherwise, you didn't
58.
wear a marksman'smedal is all. You didn't have any qualification in
the infantry; of course, it would be looked down upon in the case of
promotion or something like that. In the air wing it had much
slighter significance than that. Maybe if you were being considered
for a meritorious promotion and you hadn't qualified you wouldn't
get it, but day to day it had no significance.
Mr. Jenner. Were the standards applied in the air wing with
respect to qualifications for these three classes as severe or as high
as the standards applied, let us say, in the Marine infantry?
Mr. Thornley. Exactly the same; yes.
Mr. Jenner. Exactly the same. Would you please state for me your
concept of the degree of marksmanship for (a) marksman, (b)
sharpshooter, (c) expert?
Mr. Thornley. Well, a marksman is an average shooter. A man, I
think, could pick up a rifle and with a little commonsense and a
minimum knowledge of the basics of marksmanship qualify as a
marksman. When a man doesn't qualify as a marksman it is usually
either because he is nervous on the day of qualification or he is gun
shy or some outside influence confuses him; maybe he gets his
windage off, something like this.
Sharpshooter is just a little above average. It ranges over about
—a pretty wide field. But it is a man who—a sharpshooter would be
a man, the average man, with a good, maybe a week of training on
how to use a rifle, and some practice.
Whereas an expert is the kind of man I would hate to have on
the other side in a war. He is accurate with his rifle up to and
including 500 yards in a number of different positions. Hits the bull's-
eye or close to the bull's-eye an overwhelming percentage of the
time.
Mr. Jenner. Is that the category in which we would place that to
which we refer generally as the sniper?
59.
Mr. Thornley. Yes.Well, any man might be assigned as a sniper, I
imagine. But an expert rifleman would perform much better.
Mr. Jenner. Maybe be a superior sniper.
Mr. Thornley. Yes. Definitely.
Mr. Jenner. And to attain the position of expert marksman must
there be considerable practice and use of the weapon or is it more of
natural ability?
Mr. Thornley. Now, you enter in once again to natural ability, just
as not qualifying might be caused by a lack of natural ability of some
kind. An expert rifleman probably would have a much calmer
nervous system or, you might say, a much greater degree of control.
I would imagine training can make up for this. I know a couple
of times I just missed expert by a few points. It seemed that I
couldn't make expert. It seemed to me there was just something I
didn't have in order to make expert. It was very frustrating.
Mr. Jenner. You tried?
Mr. Thornley. Yes; it takes a great degree of control, primarily. Of
course, the other things like good eyesight and so on and so forth.
Mr. Jenner. Oh, yes.
Mr. Thornley. Yes.
Mr. Jenner. Did you ever discuss with Oswald his degree of
proficiency in the use of the rifle?
Mr. Thornley. Not to the best of my knowledge.
Mr. Jenner. Did you have any impressions that you gathered in
that respect while you were with him at El Toro?
Mr. Thornley. None whatsoever. Had somebody asked me to
guess about Oswald, I would have said, well, he probably didn't
qualify, just because that was the type of guy he was, but that is all.
Mr. Jenner. You would never have expected him to have been a
sharpshooter, for example?
60.
Mr. Thornley. Itwouldn't have greatly surprised me if he was and
it wouldn't have greatly surprised me if he wasn't. This is something
very difficult: to look at a man and tell, at least it is very difficult for
me. I have seen some drill instructors who could do it. But to tell
whether he is going to be an expert or a sharpshooter, marksman, I
am not qualified.
Mr. Jenner. While you were stationed with him at El Toro, did you
ever go off base with him?
Mr. Thornley. No.
Mr. Jenner. Did you ever have any discussion of dates?
Mr. Thornley. No.
Mr. Jenner. His attitude toward women?
Mr. Thornley. No.
Mr. Jenner. Sex?
Mr. Thornley. None whatsoever.
Mr. Jenner. Was there any scuttlebutt around the camp in that
regard with respect to him?
Mr. Thornley. Not to the best of my knowledge.
Mr. Jenner. Sex habits, propensities?
Mr. Thornley. No; you stand a risk in the Marine Corps, if you are
at all quiet and tend to be introverted, of being suspected of being
homosexual, but to the best of my knowledge there were never any
comments made of this nature.
Mr. Jenner. Do you recall some other readings of his in addition to
"1984"?
Mr. Thornley. I do recall having mentioned Dostoievsky to him
and I know he had read something and I think it was "Crime and
Punishment" but I am not sure. It was something I had not read by
Dostoievsky when I had read about, I guess at that time, about
three or four books.
61.
Mr. Jenner. Itis a great book.
Mr. Thornley. Someday I am going to get around to it.
Mr. Jenner. Have you not read it yet? It is a really great book.
Mr. Thornley. No; and I don't recall him mentioning any other
books offhand. I don't—I can't think of a thing besides "1984" and
some book by Dostoievsky.
Mr. Jenner. While you were based at El Toro did he engage, did
you notice, in any officer baiting on his part with respect, in
particular, to such matters as foreign affairs?
Mr. Thornley. Yes; not on foreign affairs, no, but the same officer,
Lieutenant Donovan, spoke of in a foreign affairs lecture in the
newspapers, I do remember him baiting him on a couple of
occasions.
Mr. Jenner. Oswald attempting to bait Lieutenant Donovan?
Mr. Thornley. I don't remember what it was. I know, I believe
Lieutenant Donovan was also a lieutenant which I had had a couple
of run-ins with if I remember correctly.
If not, it was Lieutenant Delprado. It was one of the two of
them. Mine were completely accidental and I went to great length to
keep away from one of them because it seemed like any time I was
around him I happened to do something to irritate him. But Oswald,
I don't recall exactly what he said, but he a couple or three times
went out of his way to say something to one of these lieutenants
that would cause them to be irritated and in this you can't really say
that he was exceptional. It happened many times. In Oswald's case
though, it was exceptionally——
Mr. Jenner. You mean it happened many times with respect to
other noncoms in the Marines with respect to these officers?
Mr. Thornley. Right; but in Oswald's case it seemed a little more
deliberate. Some guys would get mad and they would say
something, or sometimes they would do something by accident, and
62.
they would getthemselves involved and then they would decide,
"Well, what the hell," and push it all away. Oswald it seemed didn't
have to have any reason. He just told an officer to get lost.
Mr. Jenner. He baited an officer for the pleasure of it?
Mr. Thornley. Yes; I might mention that this was one means by
which he won the admiration of others in the outfit in that the junior
officers especially are usually disliked, or were in that outfit, and this
made him on such occasions as he engaged with an officer in some
kind of officer baiting, this won the respect, for at least a few
minutes, of the men—who would kind of laugh about it, and chuckle
over it and tell others about it. Perhaps this is why he did it.
Mr. Jenner. You mentioned some slovenliness on his part; what
about his quarters, his barracks; did you have occasion to observe
them?
Mr. Thornley. I don't think I was ever in his barracks. I do recall
having been told that he had Russian books and that is all I—that is
the only connection I can make now in my mind with his quarters. I
don't think I ever saw them.
Mr. Jenner. You already have given us something of his view of
the U.S. Marine Corps. Would you give us a summary of that? Give
us your impression of his views with respect to the U.S. Marine
Corps.
Mr. Thornley. Well, definitely the Marine Corps was not what he
had expected it to be when he joined. Also he felt that the officers
and the staff NCO's at the Marine Corps were incompetent to give
him orders.
Mr. Jenner. Incompetent in what sense, they were below him
intellectually?
Mr. Thornley. They were below him intellectually—and for various
other reasons in each case, too. Maybe this officer was ignorant, as
was brought out about foreign affairs, in Oswald's mind, knew less
than Oswald did about it. I don't hold with the stand that Oswald
63.
would study upon foreign affairs simply in order to bait the officer. I
think it just happened to be that Oswald would see that the officer
was basing his foreign affairs maybe on Time magazine when
Oswald had done a little more reading and I think he resented this
Time magazine approach to foreign affairs.
Mr. Jenner. How did these discussions arise, Mr. Thornley, the
discussion of foreign affairs by officers?
Mr. Thornley. Well, the officers, every so many weeks—this is
mentioned somewhere in this pile of papers—every so many weeks
a lieutenant is appointed to give a foreign affairs lecture or a current
affairs lecture, pardon me, to the troops, at which time he explains
the world situation in a half hour. I remember having one second
lieutenant telling us about Dalai Lama or it was a first lieutenant and
I forget what he told us, but it was something completely absurd. I
think at that time the Dalai Lama had just disappeared or
something, and one would get the impression, I think, that he
thought the Dalai Lama was a leader in Pakistan or something.
Mr. Jenner. That is the impression the lieutenant tried to convey?
Mr. Thornley. Well, I think that was the impression the lieutenant
had had when he had been assigned to give this lecture. The last
minute, he got down and started going through the news magazines
to get his information, got it somewhat inaccurately, and didn't
particularly care whether it was accurate or not anyway. Stood up in
front of the troops and reeled off the lecture, and, of course, most of
the enlisted men didn't know enough to criticize him either because
they weren't that interested, and that was it—with a couple of
people laughing up their sleeves, and this happened later, this didn't
happen at the time I knew Oswald.
However, in such a situation Oswald would have been careful I
am sure to raise his hand and correct the lieutenant.
Mr. Jenner. I was going to get to that. During the course of these
lectures did the troops as you called them engage in discussion with
the instructor?
64.
Mr. Thornley. Theywere permitted to ask questions, to raise their
hands to ask questions. And Oswald would have probably asked a
question which would have made light of the lieutenant's ignorance.
Mr. Jenner. Put the lieutenant at a disadvantage?
Mr. Thornley. Yes.
Mr. Jenner. Were you present at any times when you were at El
Toro when the lectures occurred when, at that time Oswald raised
his hand and engaged in dissertation?
Mr. Thornley. I might have been but I don't recall it if I was. I
recall being present at several lectures at El Toro, and it just might
have happened. It was the kind of thing Oswald would do and it
wouldn't even have phased me. I probably wouldn't even have
bothered to remember if it had happened. It would have been just
part of the daily routine there so I would have——
Mr. Jenner. Did you ever engage in that sort of thing?
Mr. Thornley. No; I never had guts enough to stand up and tell
an officer he didn't know what he was talking about. Behind his back
I might tell somebody that such-and-such officer didn't know what
he was talking about, but I was never quite that brash—in that
particular respect, anyway.
Mr. Jenner. What were your impressions on Oswald being
interested in music?
Mr. Thornley. Not being interested in music myself
particularly——
Mr. Jenner. I take it you had none; that is, any impressions as to
his interests?
Mr. Thornley. No, therefore, I had none; correct.
Mr. Jenner. Did you ever play chess with him?
Mr. Thornley. No.
Mr. Jenner. Did you ever see him playing chess with anyone else?
65.
Mr. Thornley. Justnow you mentioned the word "chess" as a
definite association; I think he did play chess. I can't place the
person. This—there were some other people in the outfit who played
chess. There is one name I have been trying to remember for a long
time, and I think it starts with "Win" something. "Winter" something.
I'm probably way off base there. But a tall blond corporal, I believe,
played chess and a couple of other men in the outfit played chess.
At that time, I guess at that, I knew how to play chess. I have never
been particularly interested, though, in the game so I don't—I am
pretty sure I didn't play chess with him.
In fact, come to think of it I had just been cured of playing chess
3 months before that; somebody beat me in about six moves and I
stopped playing for about a year. It wasn't me.
Mr. Jenner. While at El Toro did Oswald become engaged in any
physical altercations with anybody?
Mr. Thornley. No; definitely not to my knowledge. Never got into
any fights or even any hot personal argument over anything, that I
know of.
Mr. Jenner. What was your impression, if you had one then, as to
his disposition in that regard?
Mr. Thornley. I had the impression that he avoided violence.
Mr. Jenner. While you were at El Toro do you recall whether
Oswald ever went off the base on liberty?
Mr. Thornley. As far as I know he didn't.
Mr. Jenner. Were there any discussions on the base as to what, if
anything, Oswald did?
Mr. Thornley. Not in my presence.
Mr. Jenner. What, if anything, Oswald had done off the base on
liberty?
Mr. Thornley. Not in my presence.
66.
Mr. Jenner. Wasthere ever any discussion of Cuba and Castro
and that problem?
Mr. Thornley. Yes, sir.
Mr. Jenner. All right; tell us all about that.
Mr. Thornley. Well, at that time I and Oswald were both, and a
couple of other men in the outfit, were quite sure that Castro was a
great hero.
Mr. Jenner. Why?
Mr. Thornley. Well, he was liberating Cuba from Batista and, of
course, we had heard all about Batista and what an evil man he
was, which I am sure was true, and most of us had read some of
the things written by Castro, some of Castro's promises—such as he
would take no part in the government after the revolution, such
things—so we had the definite impression—I remember there was
one Puerto Rican boy, myself, Oswald, a couple of others who had
quite an admiration for Castro, and thought the pro-Communist
statements he was or might be making at the time, were made
simply to guarantee a little more independence for his island
because it was located so close to the United States.
In other words, I felt at the time he was playing both ends
against the middle in order to go his own way, something like
Charles de Gaulle is doing right now by recognizing Red China. I felt
it was purely statesmanship, statecraft, power politics. I didn't feel
that Castro was a dedicated Communist. Whether Oswald did or not
I don't know. He admired Castro because of the social reforms
Castro was introducing. So did I at that time.
Delgado, the Puerto Rican boy, as I recall it, was becoming
worried at that time because he was beginning to think maybe
Castro was communistic. I didn't think so. Oswald, as far as I know,
didn't have anything to say on that matter. And that is about all I can
tell you.
67.
Mr. Jenner. Well,you say that you admired Castro and you knew
Oswald admired Castro. Tell us on what you base that comment.
Mr. Thornley. Well, once again as I remember, there was one of
these afternoon discussions once again, and somebody was saying
something, worried about Castro, it might have been Delgado, it
might have been somebody else, I don't think it was Delgado that
day because I think he was defending Castro, somebody said
something against Castro, and Oswald said that he didn't think
Castro was so bad.
He thought Castro was good for Cuba, and they said why, and I
took up the argument, which was the argument I just gave you, the
naive idea I had at the time that he was playing for independence,
and Oswald remained silent, shaking his head affirmatively a couple
of times, and that was it.
Mr. Jenner. Shaking his head affirmatively with respect to the
comments you were making?
Mr. Thornley. Yes; to my argument, to my justification of Castro.
Mr. Jenner. But you recall no provocative remarks that he made in
that connection?
Mr. Thornley. No.
Mr. Jenner. Did Oswald have a nickname?
Mr. Thornley. Not that I know of except Oz sometimes.
Mr. Jenner. Did you ever hear him referred to as "Ozzie Rabbit"?
Mr. Thornley. Well, yes; I didn't realize that anybody else referred
to him as such but I always thought of him as such. He reminded
me very much of a cartoon character at that time. It was kind of
pathetic. There was something about this little smile of his, and his
expression on his face and the shape of his head, just the general,
his general appearance established a definite association in my mind
with some Warner Bros. cartoon character, I believe Warner Bros.
And I, very recently, in a discussion with someone, describing
68.
Oswald mentioned thathe reminded you of—I said: "I think there is
a character called Oswald Rabbit who appears in movie cartoons."
And they shook their head.
Now, I know where I got that particular example so I probably
heard him referred to as "Ozzie Rabbit," though I don't recall
specifically.
Mr. Jenner. Did he occasionally have a nickname or a reference
made to him attendant upon his interest in the study of the Russian
language or his interest in communism or in Russia or Soviet——
Mr. Thornley. Only he was sometimes called the Communist and
he would, sometimes I know—as far as his study of the Russian
language went he made no attempt to hide this.
In fact, he made—would make attempts to show it off by
speaking a little Russian.
Mr. Jenner. He was proud of that, was he?
Mr. Thornley. Yes; there was someone else in the outfit who
spoke Russian, don't ask me who, they used to exchange a few
comments in the morning at muster and say hello to each other or
something, and he also would make jokes in Russian, not in Russian,
but in English, in a thick Russian accent many times; this was very
typical of him.
Mr. Jenner. He resorted to that area and use of satire?
Mr. Thornley. Yes; until I had made the comment that implied he
was a Communist, I had no idea——
Mr. Jenner. That he was sensitive?
Mr. Thornley. That he was sensitive about it because he didn't
seem to be.
Mr. Jenner. Did he have any visitors?
Mr. Thornley. Not that I recall.
69.
Mr. Jenner. Wasthere any discussion at anytime about the
possibility of his going to Russia?
Mr. Thornley. No.
Mr. Jenner. This was a complete surprise to you when you saw it
in Stars and Stripes?
Mr. Thornley. Somebody would say to him, "Why don't you go
and live in Russia," in the middle of an argument.
Mr. Jenner. I didn't mean that in that sense but did he volunteer
a statement on his part about his going to Russia?
Mr. Thornley. Never anything; no.
Mr. Jenner. I take it it was your opinion he was not a Communist
at the time he was assigned to El Toro?
Mr. Thornley. That was my opinion.
Mr. Jenner. I take it you have never seen or talked with Oswald
subsequent to the time he left or you left for Japan, from El Toro?
Mr. Thornley. No.
Mr. Jenner. That is, my statement is correct.
Mr. Thornley. Yes, sir.
Mr. Jenner. It follows, I take it, that you were never aware that
he was in New Orleans when you were there?
Mr. Thornley. No; I wasn't.
Mr. Jenner. You were not aware of his comings and goings other
than the newspaper report that your folks sent you?
Mr. Thornley. I was aware that he had come back from the Soviet
Union and gone to Dallas, and I know I at that time did think about
going to see him in Dallas for the book, to find out just why he did
go to Russia, to check it with my own theory.
Mr. Jenner. I am going to get to that in due course.
70.
Mr. Thornley. Butaside from knowing that he came back and
went to live in Dallas with a Russian wife and a child I had no idea of
his comings or goings.
Mr. Jenner. At the time you had some notion of going to Dallas to
see him or Fort Worth, as the case might be, it was with respect to
the book you have talked about you were then in the process of
writing or fulminating about?
Mr. Thornley. Yes; it was practically—well, it was finished by that
time but I was thinking about, I was definitely planning to rewrite it.
I didn't know how soon, and I thought before I did rewrite it I would
go talk to him and see what he could tell me about. There were a lot
of gaps in the book, and in the book I was not able to explain how
he got from the United States to Russia and things like that. A lot of
things I wanted to check out and I thought if I could get him to
cooperate with me, perhaps not even in telling him I was writing the
book, I could get the information I wanted.
Mr. Jenner. And this was the state of mind you had after you had
heard that he returned to the United States?
Mr. Thornley. Right.
Mr. Jenner. Which was June of 1962, when he returned?
Mr. Thornley. Right, and I had finished the book in February.
Mr. Jenner. Of 1963?
Mr. Thornley. 1962.
Mr. Jenner. 1962. You were in Mexico and Mexico City in 1963?
Mr. Thornley. Yes.
Mr. Jenner. Cover that for us. What was the motivation, the
length of the trip?
Mr. Thornley. I will have to begin at the beginning on that. On
April 17, my parents sent me a gift of $100 on the condition that I
spend it for a bus ticket to visit them that summer. Which I did, and
71.
I left around—well,I arrived in California on May 5. I remember
going along the border and seeing fireworks on the other side of the
border.
Mr. Jenner. What border?
Mr. Thornley. From Yuma to San Diego.
Mr. Jenner. Mexican border?
Mr. Thornley. That is Cinco De Mayo. I arrived in California on
May 5 and I stayed there until late August. Now, I think in one of
these reports that I gave to the FBI the information might be
different. Since then I have checked with notebooks that I kept of
my activity, and I was on my way back to New Orleans in late
August. I went by way of Mexico City because I have taken 5 years
of Spanish in school and I never had the opportunity to live in an
environment where I would have to use it, depend on it solely, and I
wanted to see how I would do. I have always wanted to visit Mexico,
to see Mexico City. I checked into the prices. I had found out I had
enough money that I would be able to go down to Mexico City and
stay a short while.
So I went down there for about a week, actually it was 6 days I
spent within Mexico, from Tijuana to Mexico City, on a Mexican bus,
and then when my money began to run out from Mexico City to
Matamoros or Brownsville, Tex., on a Mexican bus.
At this time, on my way up on a bus to Matamoros, it was
September 2, because I had that in my notes, I have some notes
about the bus ride and the date September 2.
And I went from Brownsville to New Orleans by way of either
Greyhound or Continental.
Mr. Jenner. When did you arrive in New Orleans?
Mr. Thornley. I went directly to New Orleans, so I imagine I
arrived in New Orleans on September 3, possibly September 4.
72.
Mr. Jenner. Sothat between approximately May 1, 1963, and
September 4 and 5——
Mr. Thornley. Say May 3 to September 4.
Mr. Jenner. You were not in New Orleans?
Mr. Thornley. Right.
Mr. Jenner. You were returning to your home in California? You
stayed there for approximately a month or so?
Mr. Thornley. Longer than that.
Mr. Jenner. Longer than that. You then went to Mexico, Mexico
City, and you then returned directly to New Orleans?
Mr. Thornley. Yes, sir.
Mr. Jenner. During none of that period of time did you have any
contact with or hear anything about Oswald?
Mr. Thornley. Definitely not.
Mr. Jenner. You at one time at least were acquainted with a lady
by the name of Sylvia Bortin?
Mr. Thornley. Sylvia Bortin?
Mr. Jenner. B-o-r-t-i-n.
Mr. Thornley. Yes; this young lady, by the way——
Mr. Jenner. Where did she reside?
Mr. Thornley. In Whittier, Calif., or at least last summer she did, I
don't know where she resides now. This young lady, by the way, was
mentioned in—her mention in this whole matter came out of a
misunderstanding on my part of a question asked by the FBI agents.
Mr. Jenner. All right. Would you explain that, please?
Mr. Thornley. I don't recall what the question was—oh, yes, he
had asked me something about, I believe it was the First Unitarian
Church in Los Angeles. I had mentioned earlier at the time I was
73.
talking to Oswald,and knew Oswald, I had been going to the First
Unitarian Church in Los Angeles. This is a group of quite far to the
left people politically for the most part, and mentioned in order to
explain my political relationship with Oswald, at that moment, and
he began to ask me questions about the First Unitarian Church and I
answered, and then he realized or understood or asked what
Oswald's connection with the First Unitarian Church was and I
explained to him that there was none. Miss Bortin never knew
Oswald and vice versa, and these people were two different parts of
my life. There was this civilian compartment and the military
compartment, and I never intermingled them.
Mr. Jenner. This young lady married and her husband is now in
Havana, Cuba?
Mr. Thornley. That is what she told me last summer; yes. He was
going to school in Cuba.
Mr. Jenner. I take it this had nothing to do with yourself and
Oswald's views with respect to Castro that you told us about.
Mr. Thornley. No; this happened, I think, later, in fact I am sure it
happened later. At that time Miss Bortin, she was then unmarried,
did not know Robert Uname, I believe. I met him, I believe,
September a year later.
Mr. Jenner. Had you finished that?
Mr. Thornley. Yes.
Mr. Jenner. I take it that Oswald had no close personal friends at
least that you observed?
Mr. Thornley. That is correct. And the name of his closest friends
I do not know. I do remember he had a close acquaintance that he
seemed to get along with pretty well.
Mr. Jenner. In the unit?
Mr. Thornley. Yes; but I don't recall this man's name. If it was
mentioned to me, I probably could, but——
74.
Mr. Jenner. Youwere groping for it when you were interviewed.
You suggested it might be Charles——
Mr. Thornley. I mentioned a Charles.
Mr. Jenner. Weis.
Mr. Thornley. Weir, but that was not the man. This was a friend
of a friend of the friend or a man who could give them that
information perhaps that I couldn't.
At this time perhaps, also, I was thinking of a possibility it might
have been Weir and since then I have remembered definitely who
Weir was.
Mr. Jenner. Who was he?
Mr. Thornley. I don't remember whether his first name was
Charles but I remember who he was.
Mr. Jenner. He was a noncom?
Mr. Thornley. There was a man named Cooley. There was
somebody else, and these are my associations, but who it was who
used to talk Russian in the ranks with Oswald in the morning I don't
know, but that is who it was.
Mr. Jenner. Is this particular man you now mentioned the man
who occasionally talked Russian with Oswald in the ranks, is he the
man who you had in mind?
Mr. Thornley. Yes.
Mr. Jenner. As having been a friend of Oswald's?
Mr. Thornley. Yes; in that in the same respect that I was a friend
of Oswald's. Once, again, the exact terminology I would use would
be close acquaintance.
Mr. Jenner. Yes; I would say from your description of the
relationship with Oswald that it was more an acquaintanceship than
a friendship.
75.
Mr. Thornley. Ithink it was probably the same with this person
from what I recall, to my knowledge.
Mr. Jenner. In other words, when you say friend, he wasn't a
buddy of Oswald?
Mr. Thornley. No; Oswald was not the type of person who had, as
it has been emphasized on all parts, I think, and it confirms my own
impression, was not the type of person who made close friends or
who stuck with close friends.
Mr. Jenner. You saw no instance in which Oswald evidenced
affection for anybody, I mean in the nice sense of the word?
Mr. Thornley. No; none whatsoever.
Mr. Jenner. Or anybody evidenced any affection in the nice sense
of the word for him?
Mr. Thornley. No.
Mr. Jenner. I take it your trip to Mexico City was purely one of
general interest as you have described and had nothing to do with
any interest on your part in going to Cuba or attempting to go to
Cuba?
Mr. Thornley. Believe me, no. I have no desire to go to Cuba
unless I am going to take a rifle and be on an invasion force or
something.
Mr. Jenner. Did you hear of anybody in the Marine Corps, whose
last name was Hidell?
Mr. Thornley. At the time this name was mentioned to me that
was—that person, whoever it was that Oswald used to speak to in
the ranks in the morning came to my mind. But I can't say that that
was the name, and I am—of course, now, I am very leery that that
—very uncertain as to ever having heard the name Hidell, and I
doubt it very much.
Mr. Jenner. Shortly after the unfortunate occurrence of November
22, 1963, you were interviewed by Secret Service agents, were you
76.
Welcome to ourwebsite – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com