2012년 5월 5일 토요일

516) exam ple 1

http://www.flickr.com/photos/12983214@N00/2371421487/

You use Microsoft .NET Framework 4 to develop an application that uses LINQ to SQL



The Product entity in the LINQ to SQL model contains a field named ProductImage. The ProductImage field holds a large amount of binary data. You need to ensure that the ProductImage field is retrieved from the database only when it is nedded by the application.



What should you do?



Answer: Set the Delay Loaded property on the ProductImage property of the Product entity to True


LINQ to SQL DataLoadOptionsSaturday, March 29, 2008 9:24 AM


One of the good things about LINQ to SQL is that it gives the developer flexibility to choose the specified columns of a table from a database. Let's say I have table Forums and Posts and I need to get all the Forums and their Posts but I want to exclude the "Description" property of the Posts table. I want to exclude it because "Description" might be really long and loading the description will slow the fetching.



LINQ to SQL designer helps you to delay load a property as shown in the screen shot below:







Now, you can run the following query:



static void Main(string[] args)

{

DiscussionBoardDataContext db = new DiscussionBoardDataContext();



var query = from f in db.Forums

join p in db.Posts

on f.ForumID equals p.ForumID

select p;



Console.WriteLine(query);



}



And you will get the following query generated:



SELECT [t1].[PostID], [t1].[ForumID], [t1].[Title]

FROM [dbo].[Forums] AS [t0]

INNER JOIN [dbo].[Posts] AS [t1] ON [t0].[ForumID] = [t1].[ForumID]





As, you can see in the above query the "Description" column of the Posts table is not selected. If you do want to select the description column then you can tell LINQ to SQL using the DataLoadOptions feature.



static void Main(string[] args)

{

DiscussionBoardDataContext db = new DiscussionBoardDataContext();



DataLoadOptions options = new DataLoadOptions();

options.LoadWith(p => p.Description);



db.LoadOptions = options;



var query = from f in db.Forums

join p in db.Posts

on f.ForumID equals p.ForumID

select p;



Console.WriteLine(query);



http://www.flickr.com/photos/12983214@N00/2371421487/




댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...