파란실버라이트 2013. 4. 24. 21:02

Odata 를 Linq를 작성해서 바로 데이타를 볼수 있는 툴  좋다. ^^

 

In this article we will cover the simplest scenarios for connecting to LightSwitch using OData. We will not cover, inserting, updating, deleting, or validation.

The Application

clip_image001

We start with a simple LightSwitch application that contains a few Entities (tables) and Screens.

clip_image002

We Publish the application.

clip_image003

We enter some sample data.

Connecting To LightSwitch Using OData

clip_image004

We change the URL that we use to get to the application …

clip_image005

… to a URL with ApplicationData.svc.

clip_image006

This will allow us to see the OData Feed.

Using LinqPad

clip_image007

We can download and install LinqPad from: http://www.linqpad.net/.

clip_image008

We add a connection.

clip_image009

We select OData.

clip_image010

We enter the URL and click OK.

clip_image011

The Entities will show.

We can use the following query (in C# Statement(s) mode):

 

var DozenRedRoses = 
from Product in Products
where Product.ProductName == "Dozen Red Roses"
select Product;
DozenRedRoses.Dump("The Dozen Red Roses");
// Set Product ID
var intProductID = DozenRedRoses.FirstOrDefault().Id;
var OrderDetailsForRoses = 
from OrderDetail in OrderDetails
where OrderDetail.Product.Id == intProductID
where OrderDetail.Quantity > 1
select OrderDetail;
OrderDetailsForRoses.Dump("The order details for more than 2 roses");
// Get Order Detail IDs
List<int> OrderDetailIDs = new List<int>();
foreach (var element in OrderDetailsForRoses)
{
	OrderDetailIDs.Add(element.OrderDetail_Order);
}
foreach (var element in OrderDetailIDs)
{
	var OrderForRoses = 
	from Order in Orders
	where Order.Id == element 
	select Order;
	
	OrderForRoses.Dump("A order for more than 2 Red Roses");
}

 

To produce this result:

clip_image012

Security

clip_image013

We can enable Forms Authentication and deploy the application again.

clip_image014

When we try to navigate to the OData methods it prompts us for a valid account.

 

참조 :

http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/114/Accessing-Your-Visual-Studio-2011-LightSwitch-Application-Using-OData.aspx