Visual Studio Lightswitch 2012 Course Summary(one)

来源:互联网 发布:录视频的软件 编辑:程序博客网 时间:2024/06/06 02:54
Source Code:http://www.apress.com/9781430250715
IT-Ebook:www.it-ebooks.info
Chapter 1   Introducing Lightswitch
Lightswitch's Architecture
Chapter 2  Setting Up your data
1、Notice how LightSwitch Date and DateTime fields map to the SQL Datetime data type. the minimum date value
that you can store is 01-Jan-1753. if you need to store earlier dates (for example, if you’re writing genealogy software),
create your tables in an external SQL database and create columns using the DateTime2 datatype (a data type that offers
more precision and a greater range of date values).
2、Attaching to an Existing Database
1)If you find that some of your tables are missing from the dialog shown,make sure that you’ve defined  primary keys on
 those tables. Tables won’t appear unless primary keys are set up.Any views that you want to add must contain a derivable
 primary key column and can be added only in read-only mode.
2)you can’t change from SQL Server to MySQL without deleting the tables in your application and reimporting.
3)DataTime offset and unsupported data types
When you connect to an existing database, there are five SQL types that are currently unsupported. These are the
spacial data types geography and geometry, hierarchyid, sql_variant, and datetimeoffset. If you have an existing
database that uses any of these data types, LightSwitch won’t be able to read or write to those fields.
DataTime Offset:
    Datetimeoffset is the data type that gives developers the most problems. It’s commonly used in applications
that span multiple time zones, but it is currently unsupported in LightSwitch.
    If you want to create an application that supports multiple time zones, the simplest solution is to save all datetime
values in UTC (Coordinated Universal Time). You can use server-side code to ensure that all dates are saved in this
format (Chapter 4 shows you how to write code that runs on the server). The .NET datetime class contains
a DateTime.ToUniversalTime method that you can use to convert times.
Chapter 3 Introducing Silverlight Screen Design
3、The Difference between the Collapsed and None Options
4、Making Controls Read-Only
Chapter 4 Accessing Data With Code
1、Finding Single Records by ID Value
The Data Source object provides two query methods,called _single and _singleorDefault,for each entity in your data source.
These methods return a single record by ID or primary key value.The difference between single and singleorDefault  is that 
Single throws an exception if  the record doesn't exit.SingleOr Default returns null rather than throwing an exception.
2、Working with Screen Events
To handle these events,click the Write Code Button that appers in the toolbar of your screen designer.This produces a drop-
down list of methods,which can vary depending on the screen template type that you've chosen.
General Methods:
General Events: 
    The LightSwitch client triggers general events throughout the life cycle of a screen. You can handle these events in
order to write custom code that executes whenyour screen loads, closes, or carries out a save.
 InitializeDataWorkspace:
    The InitializeDataWorkspace method allows you to write custom code just before the client initializesyour  screen
 (and data workspace). You'll see examples of why you would want to do this in Chapter 7.
Saving method:
    You can use the Saving method to run your own code just before the client saves the data on the screen. When
you click on the Write Code button and select the Saving method, LightSwitch creates a method stub and opens the
code editor window. This method stub includes a parameter called handled. If  you set this to true, LightSwitch will
not perform the save operation. This allows you to carry out your own custom save logic. The "Handling Conflicts in
Code" sample later in this chapter demonstrates this concept.
Closing method :
    The client fires the Closing event just before it closes a screen. The Closing method includes a parameter called
cancel. Ifyou set this to true, LightSwitch prevents the screen from closing.
Access Control Methods:
CanRun method:
The LightSwitch client fires the CanRun method just before it opens a screen. This allowsyou to write security code
that controls who can view a screen. You'll find example code in Chapter 17.
    With some imagination, you can write code in the CanRun method to carry out tasks that are outside the intended
securitypurpose of this method. For example, you can create a dummy screen so that LightSwitch creates an entry
inyour application's navigation panel. This gives  you an entrypoint into the dummy screen's CanRun method and
allowsyou to execute Silverlight code outside the context ofyour screen object. In Chapter 17, the "Opening Screens
Conditionally at Login" example demonstrates this technique.
Collection Methods:
 Changed and SelectionChanged events:
    The LightSwitch client fires Collection events when the data in a collection changes. The typical events that you'll
handle are the Changed and SelectionChanged events.
    LightSwitch fires the SelectionChanged event when the selected item in a collection changes. You can use this
event to write code that runs when a user selects a different row in the DataGrid or List control. The Changed event
allows you to write code that runs when a user adds or deletes a rowfrom the DataGrid or List control.
Note: If you want to use these methods, you must select the collection from the left hand side of the screen designer
before clicking the Write Code button. If you don't, the collection methods will not be shown in the drop一down list of
available methods.
Screen Property methods:
    Screen property methods are executed during the life cycle of a property. They allow you to write custom code when
 a  property loads, changes, or is validated.
    For example, you can add code to the loaded method of an issue details screen that shows an alert if the issue is
overdue.
Chapter 5 Validating Data
1、Identifying Where Validation Runs
LightSwitch can carry out validation on the client, on the server, or on both the client and server. It’s important to
target the validation at the right tier. For example, if you want to write validation that relies heavily on data, it wouldn’t
be efficient to download lots of data onto the client just to perform this task.
2、Creating Validation Rules and Warning
    The AddPropertyResult method that’s used in this example allows users to save their changes after viewing the
validation warning. The AddEntityResult method also behaves in the same way.
    If you use the AddPropertyError or AddEntityError methods instead, users will not be able to save their changes
until they enter data that conforms to the validation rules.
Chapter 6 Querying Your Data
Introduction to Data Retrieval
LightSwitch Queries Always Return Entities.
If you’ve defined parameters on your query, the client will supply the necessary arguments. When the server
completes the query, the query operation will return either a single entity or multiple entities to the client.
1、CanExecute Method:
 the CanExecute method allows you to carry out security checks and apply access control rules. You can find more 
details on writing authorization code in Chapter 17.
2、Execution Method:
LightSwitch transforms the query into one that the data provider understands.  (Examples of data providers are the
 ADO.NET Entity Framework provider for SQL Server and the OData data provider  for SharePoint.) During the Execution
 phase, LightSwitch also translates business types between their underlying storage type and business type representation.
Note:
If the query succeeds, the query pipeline executes the code in the Executed method. For example, you could
write custom code here to audit the users who have read some data.
If the query fails, you can perform additional error handling by writing code in the ExecuteFailed method.
Understanding LINQ Syntax

 
 
 
                                                                                                                                                                                                                           To   Be  Continue......
 
 
原创粉丝点击