100% found this document useful (1 vote)
52 views

Full download Code First Development with Entity Framework 1st Edition Barskiy pdf docx

Entity

Uploaded by

kazzahkadhee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
52 views

Full download Code First Development with Entity Framework 1st Edition Barskiy pdf docx

Entity

Uploaded by

kazzahkadhee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Download Full ebookname - Read Now at ebookname.

com

Code First Development with Entity Framework 1st


Edition Barskiy

https://ebookname.com/product/code-first-development-with-
entity-framework-1st-edition-barskiy/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming Entity Framework 1st Edition Julia Lerman

https://ebookname.com/product/programming-entity-framework-1st-
edition-julia-lerman/

ebookname.com

Eclipse Development Using the Graphical Editing Framework


and the Eclipse Modeling Framework 1st Edition Bill Moore

https://ebookname.com/product/eclipse-development-using-the-graphical-
editing-framework-and-the-eclipse-modeling-framework-1st-edition-bill-
moore/
ebookname.com

Reverse Engineering Code with IDA Pro 1st Edition Ioactive

https://ebookname.com/product/reverse-engineering-code-with-ida-
pro-1st-edition-ioactive/

ebookname.com

Information and Communications for Development 2006 Global


Trends and Policies World Information Communication for
Development Report 1st Edition World Bank
https://ebookname.com/product/information-and-communications-for-
development-2006-global-trends-and-policies-world-information-
communication-for-development-report-1st-edition-world-bank/
ebookname.com
Describing Flowers A guide to the structure of flowers and
to their identification features Second Edition Anne
Bebbington
https://ebookname.com/product/describing-flowers-a-guide-to-the-
structure-of-flowers-and-to-their-identification-features-second-
edition-anne-bebbington/
ebookname.com

Platonism Naturalism and Mathematical Knowledge 1st


Edition James Robert Brown

https://ebookname.com/product/platonism-naturalism-and-mathematical-
knowledge-1st-edition-james-robert-brown/

ebookname.com

Mediterranean Wooden Shipbuilding Apostolos Delis

https://ebookname.com/product/mediterranean-wooden-shipbuilding-
apostolos-delis/

ebookname.com

International Tables for Crystallography Crystallography


of Biological Macromolecules 1st edition Edition Rossmann
M. G. (Ed.)
https://ebookname.com/product/international-tables-for-
crystallography-crystallography-of-biological-macromolecules-1st-
edition-edition-rossmann-m-g-ed/
ebookname.com

Developmental Psychology Childhood and Adolescence Seventh


Edition David Shaffer

https://ebookname.com/product/developmental-psychology-childhood-and-
adolescence-seventh-edition-david-shaffer/

ebookname.com
Learning iPhone Programming From Xcode to App Store 1st
Edition Alasdair Allan

https://ebookname.com/product/learning-iphone-programming-from-xcode-
to-app-store-1st-edition-alasdair-allan/

ebookname.com
Code-First Development
with Entity Framework

Take your data access skills to the next level


with Entity Framework

Sergey Barskiy

BIRMINGHAM - MUMBAI
Code-First Development with Entity Framework

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book
is sold without warranty, either express or implied. Neither the author nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2015

Production reference: 1110315

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78439-627-5

www.packtpub.com
Credits

Author Project Coordinator


Sergey Barskiy Rashi Khivansara

Reviewers Proofreaders
Erik Ejlskov Jensen Maria Gould
Andriy Svyryd Elinor Perry-Smith

Commissioning Editor Indexer


Sarah Crofton Mariammal Chettiyar

Acquisition Editor Production Coordinator


Usha Iyer Manu Joseph

Content Development Editor Cover Work


Natasha D'Souza Manu Joseph

Technical Editor
Narsimha Pai

Copy Editor
Deepa Nambiar
About the Author

Sergey Barskiy is an architect with Tyler Technologies. He lives in Atlanta, GA.


He has been developing software for almost 20 years. Sergey is a Microsoft MVP.
He holds these Microsoft certifications: MCPD, MCTS, MCSD for .NET, MCAD for
.NET, MCDBA, and MCP. He has been working with Microsoft Technologies for
over 15 years. He is a frequent speaker at various regional and national conferences,
such as VS Live, DevLink, CodeStock, and Atlanta Code Camp, as well as local user
groups. He is one of the organizers of Atlanta Code Camp. He authored articles for
Code Magazine.

Sergey Barskiy has been using Entity Framework since it was first released to
the public. He has deployed a number of projects to production that used Entity
Framework over the years. He has used the Code-First approach on a few different
projects as well. Sergey has produced an online video training course for this
technology. He has spoken on Entity Framework Code-First at a number of
national and regional conferences and events.

You can tweet to him at @SergeyBarskiy or e-mail him at sergey@barskiy.com.

I would like to thank my family for putting up with my busy schedule


during the time I was working on this book. I want to also thank Packt
Publishing for giving me the courage and opportunity to work on
this project.
About the Reviewers

Erik Ejlskov Jensen is a Danish .NET developer who specializes in .NET data
development. He is a Microsoft MVP for SQL Server and shares tips and code via
his blog at http://erikej.blogspot.com and Twitter at @ErikEJ. He is a project
manager for a number of SQL Server Compact and SQLite tools on the Codeplex site,
and he is the creator of the popular free Visual Studio add-in SQL Server Compact/
SQLite Toolbox. He also contributes to a number of open source projects, including
Entity Framework.

Andriy Svyryd was born in Ukraine, and then he moved to Mexico, where he
graduated from Universidad Nacional Autónoma de México (UNAM). His first job
was at Microsoft, where he worked on several projects related to data modeling.
He was a developer on the Entity Framework team for 4 years.
www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.com
and as a print book customer, you are entitled to a discount on the eBook copy. Get in
touch with us at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles,


sign up for a range of free newsletters and receive exclusive discounts and offers
on Packt books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface v
Chapter 1: Introducing Entity Framework 1
What is ORM? 1
A brief history of Entity Framework 3
The capabilities of Entity Framework 4
The Entity Framework architecture 5
Self-test questions 6
Summary 6
Chapter 2: Your First Entity Framework Application 7
Creating a new project that uses Entity Framework 8
Creating a new database based on .NET classes 9
Saving a new record to the database 12
Querying data in a database 15
Updating a record 16
Deleting a row from the database 17
Introduction to schema changes 18
Self-test questions 22
Summary 23
Chapter 3: Defining the Database Structure 25
Creating table structures 26
Mapping .NET types to SQL types 26
Configuring primitive properties 27
Handling nullable properties 33
Defining relationships 35
The One-to-Many relationship 35
The Many-to-Many relationship 41
The One-to-One relationship 42

[i]
Table of Contents

Self-test questions 44
Summary 45
Chapter 4: Querying, Inserting, Updating, and Deleting Data 47
The basics of LINQ 47
Filtering data in queries 49
Sorting data in queries 51
Exploring LINQ functions 52
Element operations 52
Quantifiers 53
Working with related entities 54
Filtering based on related data 54
Lazy and eager loading 55
Inserting data into the database 57
Updating data in the database 60
Deleting data from the database 65
Working with in-memory data 67
Self-test questions 69
Summary 70
Chapter 5: Advanced Modeling and Querying Techniques 73
Advanced modeling techniques 74
Complex types 74
Using an explicit table and column mappings 77
Adding supporting columns 78
Enumerations 79
Using multiple tables for a single entity 80
Advanced querying techniques 83
Projections 83
Aggregations and grouping 88
Advanced query construction 89
Paging data with windowing functions 92
Using joins 93
Groupings and left outer joins 95
Set operations 101
Self-test questions 102
Summary 104

[ ii ]
Table of Contents

Chapter 6: Working with Views, Stored Procedures,


the Asynchronous API, and Concurrency 105
Working with views 106
Working with stored procedures 110
Create, update, and delete entities with stored procedures 112
The asynchronous API 115
Handling concurrency 119
Self-test questions 123
Summary 124
Chapter 7: Database Migrations and Additional Features 125
Enabling and running migrations 126
Using the migrations API 130
Applying migrations 135
Applying migrations via a script 136
Applying migrations via migrate.exe 136
Applying migrations via an initializer 137
Adding migrations to an existing database 138
Additional Entity Framework features 139
Custom conventions 139
Geospatial data 140
Dependency injection and logging 140
Startup performance 141
Multiple contexts per database 141
Self-test questions 142
Summary 143
Appendix: Answers to Self-test Questions 145
Index 151

[ iii ]
Preface

Preface
I have been writing applications on the Microsoft platform for almost 2 decades.
Many, if not all of them, use databases to persist user data. I have used many
technologies to access data, starting with ADO.NET. Object Relational Mapping
(ORM) tools, have many advantages over ADO.NET. They allow developers to
write data access code faster and safer. ORM tools have been designed to solve
impedance mismatch problems between object-oriented programming and relational
databases. Microsoft's Entity Framework is the company's answer to the demand for
an ORM from .NET developers. This book is the guide that will help you acquire the
necessary skills to program your applications using Entity Framework.

This book centers on the Code-First approach with Entity Framework, which
has become the most common way of using the technology. Code-First allows
developers to control the entire data access layer of their applications from the .NET
code. This approach simplifies and streamlines the entire application development
life cycle, keeping developers coding inside Visual Studio, the only tool they need to
use Entity Framework.

The books starts with the basic concepts of defining the database structure via C#
and VB.NET code, then progresses to full data access. Chapters cover create, read,
update, and delete operations (CRUD) with Entity Framework. It also shows how
to update the Relational Database Management System, (RDBMS) structure, via
the migrations API. It explores aspects of data access in both .NET languages using
the Languages INtegration Query (LINQ), API. Because of Microsoft's continuous
commitment to both C# and VB.NET, the book contains examples in both languages
in every chapter.

[v]
Preface

I have been using Entity Framework since 2008, and I felt that I had the necessary
experience to write a book on the subject. I spoke on the topic on many conferences
and events and saw tremendous interest in creating a concise guide to Entity
Framework. This was one of my primary motivations in creating a shorter textbook.
I read many technical books while working in the industry, and I myself, at times,
had trouble maintaining the focus while reading 800-page technical books. They
definitely have a place in the industry and are very useful. However, I feel they
are intimidating for the developers who are just getting started with a particular
technology. My hope is that this book will get you going quickly on the new topic
and have you writing data access code in a few hours. You should be able to master
the foundation behind Entity Framework with this book quickly and easily.

What this book covers


Chapter 1, Introducing Entity Framework, gives us an understanding of what the,
Object Relational Mapping (ORM) technology brings to developers. You learn the
history of Entity Framework as an example of an ORM. We study the architecture
behind the Entity Framework technology.

Chapter 2, Your First Entity Framework Application, teaches us how to create our first
project that uses Entity Framework. We create classes that map to database tables.
We observe how our target database is created when the project is run. Finally, we
save and retrieve our first data from the created database.

Chapter 3, Defining the Database Structure, dives deep into details of mappings
between classes and tables. We create maps between properties to columns as well
as rules that govern such mappings. We define relationships between classes that
translate into relationships between tables. We exercise multiple approaches that
can be used to define the mappings.

Chapter 4, Querying, Inserting, Updating, and Deleting Data, discusses how to use the
LINQ API, that allows developers to retrieve the data from the database. We sort,
filter, and perform element operations and use quantifiers. We query related entities.
You learn the advantages and pitfalls of eager and lazy loading. We insert, delete,
and update the data.

Chapter 5, Advanced Modeling and Querying Techniques, dives deeper into modeling
and querying techniques. We use complex types to have more consistency in the
database structures. We create an explicit table and column names. We define
structures that use table and entity splitting. We use projections in queries to
make them more efficient and summarize our data. We page the data for retrieval,
breaking it up for presentation to the users. We use joins to create queries that use
related entities.

[ vi ]
Preface

Chapter 6, Working with Views, Stored Procedures, the Asynchronous API, and
Concurrency, shows how to access with database views from Entity Framework.
We query data via stored procedures using the Entity Framework API. We perform
create, update, and delete operations with stored procedures. We exercise Entity
Frameworks and the asynchronous API and learn the advantages and pitfalls
of asynchronicity. We implement concurrency handling, learning to handle the
situation when multiple users attempt to update the dame data.

Chapter 7, Database Migrations and Additional Features, shows how to enable


migrations on our Entity Framework project, creating and updating the database
schema without data loss. We use implicit migrations first, then create explicit
migrations, customizing our migration code. We use common aspects of the
migrations API, adding columns and specifying default values. We apply migrations
using multiple approaches. We create migrations from an existing database. We dive
briefly into useful Entity Framework features, not covered previously.

Appendix, Answers to Self-test Questions, contains answers to questions you will find
throughout the book.

What you need for this book


In order to run the sample code, you will need access to Visual Studio 2013. You can
use free Community Edition. You also need an instance of SQL Server 2008 R2 or
higher on your machine. The free Express edition of SQL Server can be used.

Who this book is for


This book is intended for software developers with some prior experience in the
Microsoft .NET framework who want to learn how to use Entity Framework. Maybe
you have used SQL for years, but want to write data access code more easily and
safely, using C# or VB.NET instead. This book is for you if you want to learn how
to use this Microsoft ORM to create strongly typed data access logic, or want to get
your database changes deployed with minimal effort. This book will get you up and
going quickly, providing many examples for C# and VB.NET programmers that
illustrate all the key concepts of Entity Framework.

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

[ vii ]
Preface

Code words in text, database table names, user input are shown as follows:
"You also need at least one class that represents the database itself, which will
inherit from DbContext."

A block of code is set as follows:


Public Class Person
Property PersonId() As Integer
Property FirstName() As String
Property LastName() As String
End Class

Any command-line input or output is written as follows. "If we need to get detailed
help for the PowerShell commandlet Enable-Migrations, we just need to type Get-
Help Enable-Migrations."

New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "clicking
the Next button moves you to the next screen".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it
helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention


the book's title in the subject of your message.

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 at http://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.

[ viii ]
Preface

Downloading the example code


You can download the example code files from your account at http://www.
packtpub.com for all the Packt Publishing books you have purchased. If you
purchased this book elsewhere, you can visit http://www.packtpub.com/support
and register to have the files e-mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/


content/support and enter the name of the book in the search field. The required
information will appear under the Errata section.

Piracy
Piracy of copyrighted 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 us with the location address or website name immediately so that 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
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.

[ ix ]
Chapter 1

Introducing Entity Framework


In this chapter, you will be introduced to Entity Framework. You will gain an
understanding of Object-Relational Mapping (ORM) tools and the problems
they solve. A brief history of Entity Framework will also be covered in this chapter.
We will examine the capabilities of Entity Framework and its architecture.

In this chapter, we will cover the following topics:

• ORM tools and the problems they solve


• A brief history of Entity Framework
• The capabilities of Entity Framework
• The overall architecture of Entity Framework

What is ORM?
When it comes to business software, almost all of it needs to store data that pertains to
its functions. For many decades, Relational Database Management System (RDBMS)
has been a go-to data storage for developers. ORM is a set of technologies that allows
developers to access RDBMS data from an object-oriented programming language.
There are other RDBMSes available, such as SQL Server, Oracle, DB2, MySQL, and
many more. These database systems share some common characteristics. Each system
supports one or more databases. Databases consist of many tables. Each table stores
data in a tabular format, divided into columns and rows. Data rows in multiple tables
may relate to each other. For example, a person's details stored in the Person table can
have phone numbers stored in a separate Phones table.

[1]
Introducing Entity Framework

In the following screenshot, you can see a table that allows you to store a person's
information, specifically their first and last names, along with a unique identifier for
each person. This type of storage, where similar data items are grouped together into
tabular structures is typical:

Each column can also be constrained in some ways. For example, PersonId is an
integer column. LastName is nvarchar(50) column, which means you can store
Unicode data of variable size in it, up to 50 characters. You will see in subsequent
chapters how we describe this information using Entity Framework.

The data stored in each column and row combination is scalar data, such as number
or string. When software needs to persist or retrieve data, it must describe its intent,
such as insert or select query, using the database-specific language called Structured
Query Language (SQL). SQL is a common standard for all relational database systems,
as issued by the American National Standards Institute (ANSI). However, some
database systems have their own dialect on top of the common standard. In this book,
we are not going to dive into the depths of SQL, but some concepts are important
to understand. There are some basic commands that we need to look at. These are
typically described as CRUD. CRUD stands for Create, Retrieve, Update, and Delete.
For example, if you want to retrieve or query the data from the preceding example,
you would type the following:
SELECT PersonId, FirstName, LastName
FROM Person

Historically, before tools such as Entity Framework, developers embedded SQL


language statements inside the software code using .NET languages, such as C# or
VB.NET or other programming languages, such as C++ or Java. The reason for this is
that these languages do not natively speak or understand SQL. For example, to retrieve
the data from the database and manipulate it as objects, you would write a fair amount
of code using ADO.NET, .NET Framework's data access built-in framework. You
would need to define a class to hold a person's data. Then, you would need to open
a connection to the database, create a command that uses the preceding query as its
text, execute the command's reader, and iterate through the reader results, populating
an instance of our Person class with the data from the reader. As you can see, there
would be a lot of steps involved. More importantly, the code we'd write would be
quite fragile.

[2]
Chapter 1

For example, if we change the column name in our database from FirstName to
First_Name, our code would still compile just fine, but would throw an exception
when we try to run it. Moreover, the data in the database was stored as scalar values
organized in columns and rows in a table, but our destination was an object or object
graph. As you can see, this way of accessing the data has a number of issues.

First of all, there is a type mismatch between RDBMS column types and .NET
types. Second, there is a mismatch between storage, which is a collection of scalar
values, and destination, which is an object with properties. To further complicate
the situation, our person object could also have a complex property that contains
a list of phone numbers, which would be represented by a completely different
table. These problems are collectively referred to as impedance mismatch between
object-oriented programming and relational databases.

The set of tools called ORM came about to solve this mismatch problem. An ORM
tool represents data stored in database tables as objects, native to a programming
language, such as .NET languages, C#, and VB.NET. ORM tools have many
advantages over the traditional code, such as ADO.NET code that we mentioned.
They expose the data using native .NET types. They expose related data using simple
.NET properties. They provide compile time checking. They solve the problem with
typos. Developers do not have to use SQL, a different language. Instead in the .NET
world, developers use Language INtegrated Query (LINQ) to query the data. LINQ
is simply part of C# and VB.NET languages. We will cover the basics of LINQ in
subsequent chapters. By the same token, programmers use an ORM tool's API to
persist data to the database. Finally, as we will see later, you will write less code.
Less code means fewer bugs, right?

A brief history of Entity Framework


Over the years, there have been many ORM tools entering the market; some
commercial, others open source. Microsoft developed its own tools. First one was
LINQ to SQL, which was built on .NET 3.5. This ORM only worked with SQL Server
and SQL Server Compact. Entity Framework, which first shipped in 2008, was the
second attempt. It had a number of advantages over LINQ to SQL. First of all, it had
provider architecture, thus was open to working with all relational database engines,
not just SQL Server, given that a provider was written for the engine in question.
All major RDBMSes have Entity Framework providers at this point in time.

[3]
Introducing Entity Framework

Entity Framework went through a few revisions. In the first version, only Database First
approach was supported. What this meant was that you would point the designer to
an existing database. As a result, code was generated that would contain a database
and table abstractions. In addition to the code, an EDMX file was also created. This
XML file contained Entity Data Model. It consisted of three models: logical, storage,
and mapping. The logical, sometimes called conceptual, model is the one you will code
against in C# or VB.NET. Storage model describes how data is stored in a database.
The mapping model, as the name implies, provides the mapping between logical and
storage models. If you were to change anything in the database, you would need to
refresh the generated model. The C# or VB.NET code is also generated again. The
mapping model has a class based on ObjectContext that has collection properties for
each table in the database. Each collection is a generic collection, where collection item
type is inherited from a base class in Entity Framework. Each class has properties that
correspond to columns in the matching table.

In the second revision, version 4, the Model-First approach was supported as


well. With this approach, you can use design surface to create entities, and then
the designer would produce the SQL script to generate the database. With this
approach, the EDMX file was still created, and the final result was the same as
with the Database First approach. Developers had access to the same set of
classes to give them the ability to persist and query data.

Finally, the Entity Framework Code-First approach was shipped in version 4.1. This
approach eliminated the need for the EDMX file. It also eliminated the dependency
on Entity Framework base classes that each entity in the model inherited from. As a
result, the code became more testable. This approach also eliminated the need for the
designer. You could just type your classes, and they would automatically be mapped
to tables in the database. There have been subsequent Entity Framework Code-First
releases after the the initial 4.1 version.

The capabilities of Entity Framework


Entity Framework can do a lot for us as Microsoft developers. First of all, it is capable
of exposing the database as a set of objects. It does so by utilizing a couple of key
classes. First and foremost, you need to be aware of DbContext. This class is at the
heart of Entity Framework Code-First. At a high level, it is a database abstraction.
Databases consist of tables, each consisting of rows and columns. DbContext in turn
has generic collection properties; each of which can be typed as DbSet<TRowType>,
corresponding to each table. Each object within the collection, referred to as an entity,
represents a row in the corresponding table. Columns are defined by properties of
the TRowType class that is specified as a generic argument of each collection.

[4]
Chapter 1

Once this structure is laid out, you are capable of querying the underlying database
by using LINQ queries. If you add a brand new instance of the TRowType class to its
parent collection and then save the changes using the DbContext API, this new object
will become a row in the corresponding table, where each property value of that object
will become a column value in the target row. On top of this, Entity Framework has
capabilities to represent other database artifacts, such as procedures and functions.
You will be able to query the data using functions, just like tables using LINQ again.
The question of evolving the database structure is an important one. In most cases, you
will need to add columns and tables, as your application changes. Entity Framework
addresses this need via the Migrations feature. This ability will allow you to alter
the database structure through C# code. In addition to adding and deleting tables
and columns, you will be able to add indexes. Migrations allow developers to evolve
a schema without data loss. As you can see, Entity Framework exposes everything
you need to access the data in your C# or VB.NET code without wiring SQL and
treats your database as another part of your overall application code. You can check
migrations code into source control, since it is also C# code!

The Entity Framework architecture


Entity Framework is built on the provider architecture. When a developer creates
a LINQ query using C# or VB.NET, the framework engine in conjunction with a
provider converts it into an actual SQL statement that is sent to the database. Any
given provider is the link between Entity Framework and a specific RDBMS that this
provider is written for. In this book, we will concentrate on the Code-First approach,
but this architecture is used in the Database First approach as well. Once the provider
executes the final SQL command, its results are materialized into .NET objects by
Entity Framework. Data reader is used for this purpose. It is important to understand
that Entity Framework is still built on top of ADO.NET, thus it is uses concepts such
as connection, command, and data reader. When it comes to data persistence, in other
words; insert, update, and delete functionalities, the flow is as follows: In the case of
inserts, a developer adds an instance of an entity class to the context. Similarly, an
entity previously added to the context can be flagged as changed or deleted, causing
the update or delete SQL statement to be executed against the database, respectively.
Entity Framework examines the state of each object in its context, using the provider
again to create an RDBMS-specific insert, update, or delete command.

[5]
Introducing Entity Framework

Self-test questions
Q1. Which of these problems does an ORM tool solve?

1. Types in RDBMS and .NET framework are the same


2. Impedance mismatch between RDBMS and object-orientated programming
3. Learning SQL is hard

Q2. Developers must write SQL queries to work with Entity Framework. True or false?

Q3. What is the name of the technology that Entity framework uses to apply
structural changes to the target database?

1. Updates
2. Conversions
3. Migrations

Q4. Which is the key class that represents database abstraction with the Entity
Framework Code-First approach?
1. DbContext
2. ObjectContext
3. DataContext

Q5. Entity Framework can only work with Microsoft databases, such as SQL Server.
True or false?

Summary
In this chapter, we took a look at how data is stored in RDBMS systems. We saw the
shortcomings of using embedded SQL to access the data. We understood what ORM
tools are all about and what problems they solve. We examined the history behind
Entity Framework. We saw the capabilities of Entity Framework. Finally, we had a
brief excursion into the Entity Framework architecture.

In the next chapter, we will actually build our first application based on Entity
Framework Code-First.

[6]
Chapter 2

Your First Entity


Framework Application
In this chapter, we will work through the creation of a brand new project that uses
Entity Framework. We will create classes that map to tables in the target database.
We will then insert a row into that table using the Entity Framework API. We will
also query this using LINQ. Next, we will update and delete our test data. Finally,
we will take a look at how to handle schema changes.

In this chapter, we will cover the following topics:

• Creating a new project using Entity Framework


• Adding the necessary references to be able to write Entity Framework code
• Creating a new database based on written classes
• Saving a new record
• Querying the saved data
• Deleting and updating the data in the database
• An introduction to schema changes

[7]
Your First Entity Framework Application

Creating a new project that uses Entity


Framework
First of all, it is important to understand how Entity Framework is distributed.
Even though it is an open source project, Microsoft employees curate the project as
well as write the lion's share of all the code. You can actually download the source
code from CodePlex at https://entityframework.codeplex.com/. However,
the easiest way to add this technology to your project is to use NuGet. The NuGet
technology allows anyone to create useful libraries and publish them on the web to
let other developers take advantage of it. Microsoft is in charge of publishing Entity
Framework on the NuGet website. The package is simply called Entity Framework.
In addition to the core Entity Framework, it also contains the Entity Framework
provider for SQL Server. We will work with the latest version of it. You can add it
to any .NET project. Let's just create a Console Application for our project first, and
then add the Entity Framework package to it. Create your project and solution by
going through File | New | Project, then picking either C# or VB.NET, and then
finally selecting Console Application under the Windows Desktop node, as shown
in the following screenshot:

[8]
Other documents randomly have
different content
The Project Gutenberg eBook of Preview of
Peril
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: Preview of Peril

Author: Alfred Coppel

Illustrator: Raymond F. Houlihan

Release date: January 9, 2021 [eBook #64244]

Language: English

Credits: Greg Weeks, Mary Meehan and the Online Distributed


Proofreading Team at http://www.pgdp.net

*** START OF THE PROJECT GUTENBERG EBOOK PREVIEW OF


PERIL ***
PREVIEW OF PERIL
By ALFRED COPPEL, Jr.

Like shadows, the four ships of Flotilla


Blue Three slipped through the patrol cordon
of the powerful Martian Space Force. Only
the crazy luck of their mad, medal-bedecked
Commodore would ever get them out again.

[Transcriber's Note: This etext was produced from


Planet Stories September 1953.
Extensive research did not uncover any evidence that
the U.S. copyright on this publication was renewed.]
The Second Martian War was three weeks old when the officers of
the Terran destroyer Darkside found themselves assembled in
Control and glumly aware that the Flotilla Commodore was sizing
them up. It was hard to tell just what he was thinking, but whatever
it was they had made up their minds to return it doubled in spades.
Having a Flotilla Commodore on board was actually a hardship,
particularly if as in the case of the Darkside—the ship elected was
unsuitable for a flagship. The Commodore needed cabin space for
himself and for his staff, and that meant that five of the Darkside's
nine officers would have to double up on what space was left. On
board a destroyer that meant a good deal. But more important yet
was the moral effect on the ship's company.
With a flag officer on board the easy life of an informal vessel would
vanish and something of the formality of a big ship would take its
place. The officers and crew would feel themselves under the
scrutiny of higher authority no matter how hard the Commodore
tried not to interfere with the working of the ship. And it naturally
followed that the ship's commander would lose some of the joy in
his independent command. Thus a happy ship would become a tight
one ... QED. It was a situation as old as ships and men.
So there was little joy to be seen in the faces of Commander Scott
and his officers when Commodore Hartnett stepped through the
valve followed by his staff. Nor was their anything about Hartnett's
appearance to suggest that they had been anything but right about
the manner in which Flotilla Blue Three would be handled
throughout the coming patrol. The Commodore was a model of
military correctness, a martinet moulded in two Martian Wars and
twenty years in space to a steely hardness that was disconcerting.
They saw a lean, leathery man in his late forties, dressed in
immaculate Greys that sported an apalling amount of silver braid.
Four stripes were rare aboard destroyers. Eyes that matched the
hard grey of the uniform glittered in a spaceburned face, shaded by
heavy black brows. Young Ensign Blake's heart sank as he took in
the set of the shoulders and the smooth fit of the blouse. He made a
mental note of the fact that from now on there would be no more
standing watches in sweatshirt and sneakers. He also reflected sadly
on the many pleasure jaunts that Scott was wont to let him make in
the Darkside's skeeter-boat, and bade a mental farewell to those
happy moments. The set of the Commodore's long jaw instilled more
respect for Space Force Regs in the young reservist than all the ten
orientation lectures he had received at Hamilton Spaceport. Plainly
there was a new era beginning for the TRS Darkside!
There wasn't a man on board who hadn't heard of Hartnett, of
course. A gambler in combat, he had always managed to come out
ahead of the game. His record was the record of practically every
major achievement of the Force. Most of it could be read from the
four rows of ribbons under his Command Pilot's sunburst.
There was the pale blue of the Terran Honor Medal that he'd won by
ramming a Martian dreadnaught of the Diemos class with his
crippled corvette off Io in the first Cat war. There was the red bar of
the DSM received for leading the first deep-space expedition to
reach Ariel and Oberon in the Uranian system ... that, before Blake
had been born. And the rainbow colored ribbon of the old UN patrol,
the First Martian Victory Medal, the Venerian Exploratory Medal, the
Spatial Cross; four rows of them ending up with the General Service
and Martian Occupation Ribbon.
To say, that it impressed the Darkside's green personnel would be an
understatement. The decorations showed Hartnett to be the gambler
... the lucky gambler ... that he was said to be.
All the way out to Luna Base from Hamilton Spaceport, the crew of
the flagship had been muttering about the "damned brass-hat" who
was going to disrupt the pleasant life of their beloved ship with his
unwanted, high-ranking, stinking, presence, but the iron-hard reality
of the man and the aura of confidence that emanated from him as
he stood on the steel deck of the Control, spiked their guns too
quickly. From the moments Hartnett stepped aboard, reflected
Commander Scott bitterly, the ship tightened up. From here on in it
was Hartnett's ship and there wasn't a damn thing anyone could do
about it.

Introductions were short and to the point. Most of the ship's officers
had met Hartnett's staff at the Base Officer's Club after the Captain's
Council, where the commanders of the four ships that made up
Flotilla Blue Three had met their Commodore for the first time. Scott
sighed as he thought of the evident relief on Lieutenant Morrow's
face when he had found that the flagship was to be the Darkside
and not his own ship, the Lysander.
"That Hartnett will take over your ship, Scott," Morrow had told him.
"He can't help it. From the moment he steps aboard, it'll be his
baby." And Hartnett was a gambler....
Scott presented his officers to the Commodore almost jealously,
starting with the Executive, Lieutenant Commander Chavez and
Lieutenant Horowitz, the Tactical Physicist; and ending up with
Ensign Blake, the Junior Gunnery Officer, who was startled from his
nervous fidgeting by the sound of his name.
"A reservist," was Hartnett's only comment, and though it was said
in a friendly tone, Blake flushed furiously and wondered if it stuck
like straw out of his ears.
"Mr. Blake is the Charles Blake who won the New York to Ley City
amateur skeeter-boat race last year, Sir," explained Scott.
The Commodore nodded vaguely, his eyes wandering over the
burnished chrome and steel of the Control panels. "Good sport,
small ship racing, Mr. Blake," he commented.
Blake's cherubic face burst into smiles. "The best sir!"
Hartnett's men were presented to the ship's commander more as a
formality than anything else, as he had met them before. Thorne, a
full Commander, was Flotilla Astrogator, Wilson and Orsov,
Lieutenants, were Flotilla Gunnery Officers, James, a jaygee, was
Flotilla Signals Officer, and Ensign Ward, a thin boy about Blake's
age, was the Commodore's Aide. He sported his single silver
augilette proudly.
They didn't seem a bad lot, reflected Scott grudgingly. Maybe they
wouldn't get in the way too much.
"We can lift ship as soon as convenient, Mr. Scott," said Hartnett,
issuing his first order.
"Aye, sir."
Hartnett turned to his staff. "Get yourselves below and sort
yourselves out. Try not to take up too much room." As they vanished
down the ramp, he turned to take a seat at the visiplates.
Scott was taking a time check from the Tower Control, and the
signalmen were relaying the lift-ship order to the three other ships of
Blue Three. Outside on the airless field, the amber warning lights
were spinning on the Tower mast, warning the spacesuited
maintenance crews away from the blast pits.
Chavez was snapping orders into the intercom and the Darkside was
awaking to activity smoothly. Five shielded decks below Control,
Chief Jetman Collins and the black-gang were busily removing the
seals from the cadmium dampers in the blast chambers. The "three-
minutes-to-lift-ship" alarm blared and the lights dimmed, leaving
Control lighted only by the reflected glow of the panel lights. On the
visiplate screen, the slender shapes of the Lysander, the Argus and
the fat, ungainly silhouette of the ironically named Artemis showed
clearly in the earthlight.
The Artemis, thought Hartnett, was the only weak link in his
command. The other three ships were modern, but the Artemis was
an ancient alcohol burner, converted to atomics and pressed into
service by the exigencies of an undeclared and treacherous war.
At best, she could stand no more than 5 Terran Gs and the rest of
the Flotilla would be forced to keep to her reduced speed throughout
the cruise. Her armament was lighter and her armor thinner than it
should be. In fact, she was strictly Cat meat if she should ever be
forced to stand and fight. And if they intercepted any Cats, that is
exactly what she would have to do, since she was the only ship of
Blue Three that could not outrun any comparable Martian ship.
Scott was giving his orders now, eyes fastened on the master
chronometer. Hartnett was pleased to see that he did so without a
sidelong look at his superior. He knew his business and did it. Good.
Then Hartnett could stick to handling Blue Three and worrying about
the Artemis without thought of how the ship under him was being
managed.
He slipped into his G-Suit and plugged the lines into an outlet on the
side of his chair. The second hand swept up the face of the dial, and
Scott hit the firing studs. Far below, Jetman Collins removed the
dampers from the main blast chambers.

The takeoff was strictly routine for the Luna Base personnel. The
four ships of the Flotilla rose from the pits on their long tails of
radioactive flame, setting the outside Geiger counters to clucking
wildly and outlining in vivid relief the three dreadnaughts that lay in
their careening berths and the dozen or so smaller ships on the line.
Under 3 Terran Gs of acceleration, Flotilla Blue Three was soon lost
in the ebony sky. For just an instant there was the vaguest
suggestion of four racing shadows on the blue-green disk of the
gibbous Terra that hung low in the heavens, and then nothing. The
airless silence of Luna Base continued unbroken.
In the sheathed Control Tower, the Operations Officer made ready to
go off watch. He was thinking of a few drinks and a girl and maybe a
thick steak down in Ley City. Wonderful place, Ley City ... even in
wartime.
The door burst open, but it was not his relief. It was a breathless
yeoman of signals. He held a sheaf of papers in his hand.
"Has Blue Three lifted, sir? Cryptographing sent me with this."
"Damn! They're well out by this time Reilly." He indicated the radar
screen that showed four rapidly moving pips already heading into
deep space.
The yeoman handed him the papers without a word.
"What kept you?" The officer demanded angrily.
Reilly looked at his superior reproachfully. "I made it from Crypto in
forty seconds flat, sir. Couldn't come any faster!"
"Dammit! Now we'll have to put this on tight beam and scramble it.
Intelligence suspects the Cats have cracked our cipher!"
He sat down at the scrambler and began to type.
"COMMODORE CLARE HARTNETT: ABOARD TRS
DARKSIDE FLOTILLA BLUE THREE. PRIORITY MISSION.
REPEAT. PRIORITY MISSION. SPATIAL INTELLIGENCE
REPORTS LARGE QUANTITY ISOTOPE X-R REFERENCE
6589-3 CODE BOOK IN DANGER OF CAPTURE AT
METALLURGICAL STATION 9 CHART REFERENCE A-5.
PREVENT AT ALL COSTS. LARGE CONCENTRATION
MARTIAN PHOBOS CLASS CRUISERS AND POSSIBLE
SUPERDREADNAUGHT ARMED WITH CYCLOTRONICS IN
VICINITY SEARCHING FOR STATION 9. REPEAT. X-R
MUST NOT FALL INTO MARTIAN HANDS. DESTROY IF
NECESSARY. FOR YOUR INFORMATION AND GUIDANCE
INTELLIGENCE SUSPECTS CIPHER TWO HAS BEEN
CRACKED BY MARTIAN CRYPTO. LUCK. DO NOT
ACKNOWLEDGE. SIGNED: TORAN LONG, CAPTAIN,
SENIOR CONTROL, LUNA BASE. END MESSAGE."
Rising, he detached the roll of perforated tape from the scrambler
and fed it into the tight beam transmitter. When the roll was
consumed, Long dropped sullenly into a chair. His relief arrived, but
all desire to partake of the joys of Ley City was gone. Like most of
the old timers he admired Hartnett immensely, and he could not rid
himself of the feeling that he was in some way responsible for
sending the fabulous spaceman into sure destruction.
Against the ten known cruisers and the suspected superdreadnaught
that were searching that quadrant for the illusive Station 9, the
strength of Flotilla Blue Three was sadly inadequate.
If the message had arrived earlier, a dreadnaught or at least a
couple of cruisers could have been despatched with Hartnett's force.
But the impossibility of a rendezvous in space made it strictly the
Commodore's baby now. Besides, Terra had no ships to spare.
Hartnett would have to rescue the three technicians at the Station
and destroy the Isotope X-R with no help.
The Cats didn't know what X-R was, but they wanted to find out
awfully badly if their concentration of strength in the Uranus
quadrant was any indication. And it wouldn't be very long before
they found that the mysterious Station 9 was on Oberon, either. With
more than eleven ships prowling around, they wouldn't miss such an
obvious bet for very much longer. All Hartnett had to do now was
sneak through their screen, land a ship on Oberon, take the
technicians off, destroy the X-R, and get away again without being
seen because the Artemis couldn't fight! Long groaned. That's all!
Oh, why, he wondered, wouldn't Terrans learn? An ancient leader of
Terra's nationalist era had said it perfectly for them. Speak softly, he
had said, but carry a big stick! Why wouldn't they listen?
He shook his head and left the Control Tower wearily.
"What's eating him?" asked the relief.
"He's just sent Blue Three into the Uranus quadrant," replied Reilly.
The relief gave a low whistle and turned to look out over the earthlit
moonscape. "Too bad."
Hartnett caught the Commander's eye as he worked at the control
board.
"Sorry to crowd you like this, Mr. Scott," he said.
"It's nothing at all, sir. It's a pleasure to have you aboard." Even as
he said it, Scott realized how stupid it must sound. Of course it
crowded him to have Hartnett aboard and it annoyed him being the
second ranking officer on his own ship.
Commodore Hartnett smiled at the Commander's words. There was
hardly anything else he could say, poor devil. Rank has its privileges,
he thought. But he said: "Glad you feel that way," and fell silent
watching Scott and the Quartermaster guide the ship through the
first stages of acceleration.
Scott felt he should say something more, but he wasn't at all sure
just what. Finally he said, "We've only an hour or so more of
acceleration, sir. If there's anything you want tied down in your
cabin, you'd best notify Mr. Ward. The Darkside has no gravitators."
"The cabin will be in order, Mr. Scott," replied Hartnett casually, "My
staff and I are all destroyer men."
Scott cursed himself for an idiot and mumbled an apology, but the
Commodore had let the incident pass with a half hidden smile and
was inspecting the orbital calculators at the far wing of the Control
panel.
The voice of Lieutenant Morse, Astrogation Officer, saved Scott any
further embarassment. The communicator buzzed and Scott closed
the switch.
"Control here!" he snapped, a bit too crisply.
"Astrogation. We'll be at the boundary of our inner patrol zone at
2335 Sidereal, sir."
Scott looked over at Hartnett. "Any orders, sir?"
The Commodore shook his head. "Just have the other ships maintain
visual contact. Particularly the Artemis. The Lysander can take the
rear position. Have me called in my cabin if anything comes up
before then. See you in the wardroom at dinner. Carry on, Mr. Scott."
He left Scott feeling sorry for his friend, Tom Drew, who commanded
Blue Three's lame duck, the beloved Artemis.

Striding down the ramp, the Commodore came to the main gun-deck
and headed aft, past the banks of five inchers and torpedo tubes
that lined the inner shell. The gun crews stood respectfully as he
walked past them and returned young Blake's sharp salute. Hartnett
restrained a smile and continued down to the cabin deck.
Ensign Ward was unpacking his gear as he came through the valve,
and listening to a commercial broadcast on short wave that crackled
and faded with the vagaries of Terra's faraway heavyside layer. The
reports, pieced together, gave a fairly comprehensive picture of the
fighting that was going on in the Uranian quadrant.
"I don't like the way things are going, sir," said Ward.
Hartnett didn't either, but he could see no point in saying so.
Besides, the Flotilla's patrol area was on the other side of the sun
from Uranus, and the news there was bad enough to give him food
for thought.
"I won't need you for a bit, Ward. Take off and get yourself settled,"
he suggested.
The aide saluted and left. Hartnett stripped off his blouse and shirt
and settled himself comfortably on the acceleration bunk. He
switched on the bank of solar lamps and let the warm rays sooth
and relax his tired muscles. The tension of many harrowing days in
the Pentagon began to leave him, and he felt a great pity for the
desk-bound VIP who could not know the joy of a ship under them in
deep space. Thank God he got past the last physical. They were
getting tougher every patrol!
The radio was still on and as the news reports came in, his restless
mind turned to consider the unfortunate tactical situation in which
the Terran Space Force now found itself.
It was the old democratic failing. God Bless it! As old as Terra's
history. Ship for ship and man for man the Terran Forces were better
than the Martian. Terrans shot faster and straighter. Terran ships
flew farther and faster. And Terra, for all its failings, was a free world
fighting for a free space. But the Cats had more ships and a hell of a
lot less reluctance about using them to enslave everybody in sight.

The first Martian war had ended the squabbling confederation of


sovereign states that had been the UN. And the Martian war had
brought about in five short years the advancement of space-flight
that might otherwise have taken decades. It was ironic that the
peace-loving peoples of the Universe always seemed to produce
better under the harsh goad of war. The nastier the war the more
magnificent the achievements. Hartnett wondered if that were not a
very significant commentary on the true nature of the human
organism.
But in the first Cat war the Solar System had been faced with the
unfortunate situation of two races developing interplanetary flight
within a decade of each other ... and both starting out to proselytize
their own peculiar institutions among the outposts of the System. A
clash was inevitable ... and Terra won the narrow margin of victory
by a more comprehensive understanding of material science. While
the war had begun with chemical fueled ships and bombs, it had
ended up with atomic powered ships and proton cannon.
The primitive ships of the war's beginning were still vivid memories
to Hartnett. He had spent many months in them, suffering the
effects of free-fall for weeks while they coasted in half-computed
orbits around the sun. The people of Terra had long had atomics,
but it was not until the third year of war that a method had been
found to utilize the power of the atom for a space drive. In those
days a ship did not dare even a perihelion passage, for fear the
terrible heat of the sun would detonate their precious reserves of
fuel. Things were different now.
Ward reentered the room abruptly. "Message from Luna Control, sir,"
he said, passing over the note. "Came on tight beam, coded, and
scrambled," he added unnecessarily.
The Commodore read it over slowly and pursed his lips. He swung
his legs over the side of the bunk and reached for the intercom.
"Control."
"Control here," came the reply.
"Stand by for a change of course. Be with you in a moment."
There was a moment of surprised silence, and then: "Aye, sir."
Hartnett turned to his aide. "Reach me that space-bag, will you
Ward? That's the one. Fish out Code Book 6589 and the A chart.
That's the deal."

Hartnett's staff and all of the Darkside's officers not actually on


watch assembled in the wardroom on the Commodore's orders. The
Flotilla had already come about and was heading sunward, its steady
acceleration of 3 Gs aided by gravity. Already, Greys had been
packed away in deference to the rising temperature, and all hands
were clad in fiberglass shorts and jumpers.
The assembled officers rose when the Commodore entered the room
and he waved them back to their seats, taking a chair at the head of
the mess table.
"Mr. Scott," he began without preamble, "What do you know about
the new Cat superdreadnaughts?"
"Very little, sir. I have heard that they are the biggest thing in space
... although I don't believe they have more than one in service right
now. The other two of that class were photographed by a photo-
recon skeeter out of the Gorgon a week before we lifted ship. I saw
the prints."
"What about armament?" asked the Flotilla Gunnery Officer, Wilson.
Scott shrugged. "We know very little about that. Mr. Horowitz could
tell you more. I understand they mount some kind of new
cyclotronic rifles."
"That's correct, sir," replied Horowitz. "I don't know exactly how the
things work, but I could guess that they detonate the heavy metals
used for fuel in atomic powered vessels."
"Range?" asked Lieutenant Orsov laconically.
"No information ... but I would be willing to guess that it is not more
than fifty miles no matter how tight their beam. There would be far
too great a voltage loss."
"Mr. Blake," said Hartnett, "How good are you on the skeeter-boat?"
Blake looked perplexed, but he answered with some pride that he
was considered quite passable.
"I'll bear that out, sir," said Scott drily. "Mr. Blake is something of a
hotshot pilot."
"Good enough," returned Hartnett. "We'll see when we near Station
9." He looked over at Blake. "Do you think you can land a skeeter
there and take off three passengers without arousing the Cats?"
"A skeeter is only meant for three people, sir, and four would be
quite an overload," protested Blake.
"It will have to be done. If we try to land a ship there, every Cat in
the quadrant will be on our necks. It's either the skeeter, or ..." he
shrugged expressively.
"If we strip the boat down and remove all unnecessary mass it
should do," suggested Orsov. "What do you think, Blake?"
Blake gulped. To strip the skeeter would mean removing all armor
and guns. "I ... uh...." He squared his shoulders and grinned
sheepishly. "It would," he declared finally.
"Good," said the Commodore.
"Just where is this Station 9, sir?" asked Morse.
Hartnett ignored the question, but by way of answer, he turned to
his Flotilla Astrogator, Thorne and asked: "Do you remember the
analysis of Oberon's surface, Thorne?"
"Vaguely. All four of the Uranian satellites are composed mainly of
pitchblende and similar ores. Heavy metals. Very dense. I happen to
remember because it's one of the coincidences of astronomy that
the planet itself was given the name Uranus before the discovery
that the whole of its system was lousy with uranium ores."
"What else can you tell us about it?"
"Well, Oberon is small ... about 800 miles in diameter. Ariel and
Titania are about 1,000 and 600 respectively, and Umbriel is the
baby at about 400 miles. Much of Terra's uranium was brought in
from Titania back in the days of U-235 bombs and so forth. They are
abandoned now."
"Gentlemen," said Hartnett, facing the others seriously. "There are
ten Martian cruisers and a superdreadnaught in the vicinity of
Oberon and Ariel ... you may have guessed by this time that our
mysterious Station 9 is on Oberon. My orders are to rescue the three
technicians and destroy their samples of Isotope X-R, which is, I
understand, a very unstable Isotope of plutonium.
"If we could ... in some way ... destroy the bulk of the Cat strength
in the Uranus system, it would be a great step forward toward the
successful conclusion of this war that is still young enough to have
killed relatively few people."
Scott looked around at his officers and read plain astonishment on
their faces. To talk of destroying such a Martian fleet with four tiny
ships was madness!
"The rescue of the Station personnel will be handled by Mr. Blake
and the skeeter-boat. And ... if the plan I have works out properly,
the destruction of the enemy fleet will be handled by ... one ship
alone." He looked around the table with the vaguest suggestion of a
grin on his leathery face. He nodded his head at Scott. "You're quite
right, Mr. Scott, the Artemis."

Scott paced furiously up and down the steel deck of the dark
Control. Chavez sat before the panels, his saturnine face wreathed in
demon-like curls of blue smoke from the short, black, Mexican
cheroot he smoked so lovingly.
"You should have heard him!" exclaimed Scott, "Standing there and
calmly telling us that we are going to destroy the Cat fleet with the
Artemis! Booby trap 'em, he says! Chav, I tell you he's gone looney!"
Chavez shrugged and smoothed his hairline moustache. "Quien
sabe?"
"What the hell do you mean 'Quien sabe!' Are you trying to tell me
you're thinking he can do it?"
The Latin smiled, showing animal white teeth. "I understand he's
done a lot of things that people said weren't possible. Personally, I
should be very glad if he did what he says so we could all get back
to Ley City. Amigo, I have a little friend back on Luna that is." He
smiled dreamily and kissed his fingertips.
"I think you're all going crazy. It's just having that man aboard."
"Ah, Ah!" cautioned Chavez, "Remember all those beautiful silver
stripes."
"Well, damn the lot of you. I just hope we get the Darkside back to
Luna Base and your little...." He made an angry parody of Chavez's
romantic gesture.
"We'll get back, I think, Mr. Scott," said a casual voice from the
Valve. The Commodore was standing in the arch, outlined against
the ramp light. He stepped into Control and took a seat beside
Chavez at the panels.
Scott and Chavez maintained an embarrassed silence. Hartnett
looked up to study the now receding solar disk through the tinted
visiplate. The Flotilla was now heading once again for deep space.
It was a few moments before Hartnett spoke. When he did, it was a
command directed at Scott.
"Mr. Scott, the Flotilla will land for certain necessary readjustments
on Hyperion. See that the other vessels are properly notified." Then
he rose and left the Control.
Scott dropped unhappily into a chair. He looked at Chavez. "Well, Mr.
Chavez. How do you think you will enjoy command of the Darkside?"
Chavez laid a friendly hand on his commander's sleeve. "I don't think
he'd take your ship from you just because...."
"Skip it, Chav!" snapped Scott and he left the Control in peevish
silence.

Sixty hours later Blue Three lay grounded in a jagged little valley on
airless Hyperion. Spacesuited figures swarmed about the clustered
ships transferring personnel from the Artemis to the other ships, and
rigging special television, remote control, and other apparatus in the
Artemis.
Hartnett stood beneath the Darkside's ventral valve on the metallic
soil of the little moon with Chavez and Orsov watching the progress
of the work. Lieutenant Morrow of the Lysander and Lieutenant
Griggs of the Argus joined them and stood in silence while the last of
the Artemis' personnel was transferred into the Darkside. Tom Drew,
the commander of the Artemis stood sadly apart watching the
spacemen make a ghost ship of his command.
On the eastern horizon, Saturn was rising into a black sky studded
with points of fiery brilliance. Quickly the ringed planet climbed into
the sky and flooded the tortured landscape of Hyperion with light.
The men at the Darkside's valve stood watching the show of celestial
grandeur in awe. Orsov, for all his deep-space experience, could not
help but feel a twinge of vertigo as he looked up into the haloed face
of the heavenly giant that filled a quarter of the inverted bowl of
ebony that the heavens had become.
Everyone was relieved to lift ship, however, for the thought of being
caught grounded by any roving Martian spaceship was not pleasant
to contemplate. Atomic bombs had long been obsolete, but one such
would certainly suffice to exterminate four grounded spacecraft.
Then too, they were all glad to get away from the glaring spectre
that so eerily filled too much of the sky ... the ringed Saturn had a
hypnotic effect that left a man shaken.
In the Control of the Darkside Chavez whispered to Scott: "We were
thinking that you were going to lose the Darky ... and it turns out
that poor old Drew is the one who lost his command."
"He should be glad to get rid of it."
"But what," asked Chavez, "is the old man going to do with her?"
Scott shrugged and spoke succinctly. "Bait." His spirits had risen
considerably when Hartnett had left him in command of the
Darkside, contrary to his expectations. He reflected somewhat
ruefully that it did a man good to have a scare thrown into him from
time to time. Even now, rapidly approaching a quadrant heavy with
Cat warships, he could feel contented in merely feeling his beloved
tin can responding under his hands on the control panels.
A thousand yards behind and astern, the unmanned Artemis
followed the Darkside like a dog on a leash, its myriad functions
controlled by an invisible chain of subetheric impulses from jerry-
rigged remote controls on the Darkside's gun-deck.
In the faint light of the faraway sun, where the irrepressible Blake
had sloshed paint on her flank, gleamed the legend: BOOBY TRAP.
Like shadows, the four ships of Flotilla Blue Three slipped through
the patrol cordons of the Martian Space Force. In the infinite
vastnesses of the interplanetary deeps they were unnoticed. Blast
tubes silent, guided only by the ever increasing gravitational
attraction of mammoth Uranus, and the reaction of whining
gyroscopes.
Beneath them, its greenish disk ever increasing, lay Uranus ... cold,
harsh, forbidding. The thick atmosphere of methane and ammonia
lay in great turbulent belts, whipped to maniacal fury by the eternal
storms that swept the unguessable surface of the ghastly planet.

Blake shivered slightly as the skeeter-valve of the Darkside closed


soundlessly behind him and the blackness of the void closed in about
the tiny boat. For just an instant, the familiar shape of the destroyer
loomed comfortingly in the faint light of the dwarfed sun, and then it
was gone, and he was falling away towards the mystery shrouded
world that lay beneath him. The very size of the disk was
frightening. A huge swirling mass 30,000 miles across seemed to be
drawing him inexorably into its gassy body.
With an effort he settled himself down in the control chair and
patted the tattered pin-up picture on the panel before him. It was a
bit of Terra far from home, and the simple act gave him courage.
This was certainly different from the Terra-Luna flights he had so
often made alone ... this was different. He grinned to himself and
spoke aloud the phrase made famous by ten thousand generations
of actors and hacks. This, he declaimed, is it!
Quickly now, he set up the constants for Oberon and pressed the
firing stud. There was a sickening feeling in the pit of his stomach as
the skeeter came alive and the vast disk of Uranus vanished from
the forward vision ports. Speed was essential now. His trail would
not mark the place of the Flotilla, but it surely would arouse the
sharp eyes of the Cats who must be nearby. He pressed the second
stud and the skeeter leaped ahead. The accelerometer stood at 7
Terran Gs. By long practice he could stand 11 ... and the skeeter ...
stripped and souped up ... could produce 20. Far too many.
He set the seat to prone position. Maybe he could squeeze an extra
one out of it now. 12 G! He gave the skeeter more power and the
stars seemed to go into a crazy dance as his vision started to fail.
Enough.
Thirty minutes of terrific speed and still no sign of the Cats. The tiny,
dark disc of Oberon grew with alarming rapidity in the port. He
began to decelerate so fast that he nearly blacked out again. Damn!
Below him the tiny moon lay barren and bizarre in the greenish glow
of its huge primary.
The mushroom shaped huts of the metallurgical station were directly
below him and he swung the skeeter into a wild approach that
would have given his rocket instructor heart failure, but the boat
held together and settled to the surface of the tiny spaceport with a
crunch. Without waiting even for the surrounding soil to cool, Blake
was out of the ship and clumping clumsily toward the distant huts.
The terrific density of Oberon made the gravity almost normal. Three
suited figures appeared from the valves and began to run
grotesquely toward him. He waved them back and began shouting
instructions at them on the photophone. The infrared lamps on the
top of the helmets blinked eagerly in answer. Then quickly the four
men vanished into the storage hut and set feverishly to work.
Control was lit only by the red battle lamps. Lines were strung along
the walls and through the valves, and Scott, Chavez, and the
Quartermaster sat strapped at the panels. The ship was in a free
falling orbit around Uranus, its sister ships and the ghost ship,
Artemis, following her lead like huge beads on an invisible string.
The orbit could not be broken until Blake returned with the Station
technicians. All hands sat in nervous silence at GQ while the Flotilla
hung dead in space.
Commodore Hartnett came through the valve from the gun-deck.
There was a flimsy in his hand and he pulled himself along the
guide-line with some difficulty.
"Mr. Scott," he rapped out. The waiting was taking its toll of his
nerves as well as the other's. "Mr. Scott. You will break radio silence
and transmit this message immediately. Unscrambled and in Code
Two."
The men at the panels stiffened in surprise. So far they had
managed to avoid arousing the prowling Cats ... but now this!
"Sir," protested Scott, "You surely can't mean to break radio silence
with young Blake down there!"
It was hard for a man to look dignified floating in midair ... but
somehow Hartnett managed it. "It's an order, Mr. Scott."
Scott flushed angrily. A gambler! Damn you, he thought! But he bit
his lip and reached for the message. "Yes, sir."
Hartnett remained behind him as he rang for communications.
"Communications here!"
"Stand by to transmit."
"Spread beam," ordered Hartnett.
Scott cursed silently. "Spread beam."
"Aye, aye, Sir...." The voice of the radioman sounded strangled.
Scott read from the flimsy in a flat voice, a note of astonishment
creeping in as he finished the message.
"TORAN LONG, SENIOR CONTROL, LUNA BASE. AM
STANDING BY OFF OBERON READY TO LOAD ISOTOPE X-
R ON BOARD DESTROYER "ARTEMIS" HAVE NOT MET
THE ENEMY AND HAVE SUFFERED NO CASUALTIES. ONE
AUXILIARY TUBE ON THE "ORION" HAS BLOWN BUT THE
"JOVE" AND "MINERVA" ARE STANDING BY TO EFFECT
EMERGENCY REPAIRS. HAVE DOCK SPACE AVAILABLE
FOR REPAIR OF "ORION" L PLUS 21 2235 SIDEREAL.
SIGNED C. HARTNETT COMMODORE RED SIX. END
MESSAGE."
Scott wondered wildly if Hartnett had not suddenly lost his mind.
Red Six was the Code name for the Task Force that included five
Terran dreadnaughts, and the part about the blown tube and the
repairs added up to just so much lunacy. The Cats had the cipher ...
there wasn't much doubt of that, and had Hartnett invited every
Martian captain in the quadrant to come blasting down on them with
all tubes blowing, he couldn't have phrased it better!
Leaving the stunned Scott to ponder his strange madness,
Commodore Hartnett hurried down into the cluttered gun-deck.
Drew, at the remote controls of the Artemis, was ready for action
when he arrived. Time was important now, thought Hartnett.
"Now get that can down there ... and fast!"
Drew and his men went into action, and the Artemis vanished from
the string of beads and plunged toward Oberon ... an empty and
forlorn bait for a trap whose jaws were beginning to close as from all
over the quadrant, Cat warships converged on Oberon ... their
vaunted superdreadnaught in the lead.
Twenty minutes after Artemis left the Flotilla, the radioactive streaks
of the first Martian cruisers showed in the sky 15,000 miles away.
Blake and the three technicians from Station 9 huddled in the
careening skeeter-boat. They were almost on top of the Martian
superdreadnaught before they saw it. For just a fleeting instant it
seemed to fill all of space, and then it was gone. The Cats on board
paid no attention to a tiny boat that they imagined to be the survivor
of the battle that must have already begun off Oberon. But Blake
paled at the very size and might of the craft. From what he had seen
of it it would take much heavier stuff than the Darkside carried to
dent that monster!
Then they were nearing the Darkside and Blake had his hands full
threading the skeeter back into the valve that yawned black as he
drew near. Once aboard, he slipped through the sighing valves and
into the boat deck. A steward came to take charge of the
passengers, and Blake hurried up to the gun-deck that had been
transformed into the extra-corporeal brain of the doomed Artemis.
Hartnett looked up from his work to grunt at him: "Did you do what
I told you to do?"
Blake grinned, "Yes, sir. All the stuff is buried in the storage
chambers directly under the pits ... the ones that are used to store
the coolants."
"Good enough." He rang for Control. "Have we been sighted yet?"
"No, sir," came Chavez' voice. "But the Cats are gathering thick and
fast."
Blake told Hartnett about the mammoth superdreadnaught, and the
older man smiled. "We'll see if we can't give them something for
their trouble." He turned back to the communicator. "Chavez, see to
it that we maintain a mean distance from Oberon of at least 25,000
miles. And have all the screens in place."
"Aye, Sir."
"Artemis is down, Sir," reported Drew.
Hartnett turned to look into the visiplates. The derelict ship had
landed nicely on the spaceport near the metallurgical station. He
nodded with satisfaction. At least the blast of her tubes hadn't
detonated the pile. He looked into a sky plate and saw that she had
not landed a minute too soon.
Two Martian cruisers, their black shapes dark against the starry sky,
were hanging low over her. Others circled behind them, and higher
than all the others, Hartnett could make out the huge shape of the
superdreadnaught that Blake had seen. That was the one he
wanted!
For perhaps twenty minutes the Martians hung suspiciously over the
still landscape of Oberon. Then a cruiser detached itself and began
to sink down towards the spaceport on a long, slowly diminishing
column of flame.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like