LINQPad는 다른 클래스 (예 : LINQ in Action 샘플의 Books)를 어떻게 참조합니까?
필자는 LINQPad를 사용하여 bulding중인 응용 프로그램에서 LINQ 쿼리를 만들고 있습니다.
다운로드 한 LINQ in Action 샘플 (예 : 4.04)에서 intellisense가 "Books"클래스를 표시하지만 LINQPad 도구에서 참조 또는 " using "문을 볼 수 없습니다 . 다음은 샘플입니다.
List<Book> books = new List<Book>() {
new Book { Title="LINQ in Action" },
new Book { Title="LINQ for Fun" },
new Book { Title="Extreme LINQ" } };
var titles =
books
.Where(book => book.Title.Contains("Action"))
.Select(book => book.Title);
titles.Dump();
"LinqBooks.Common, Business Objects, Book.linq "에서 클래스가 정의 된 것처럼 보입니다.
public class Book
{
public IEnumerable<Author> Authors {get; set;}
public String Isbn {get; set;}
public String Notes {get; set;}
public Int32 PageCount {get; set;}
public Decimal Price {get; set;}
public DateTime PublicationDate {get; set;}
public Publisher Publisher {get; set;}
public IEnumerable<Review> Reviews {get; set;}
public Subject Subject {get; set;}
public String Summary {get; set;}
public String Title {get; set;}
public String Test {get; set;}
public override String ToString()
{
return Title;
}
}
하지만 어떻게하면 내 클래스에서 복사 할 수 있고 LINQPad를 사용하여 LINQ 문을 빠르게 빌드 할 수 있으며이를 내 애플리케이션으로 다시 복사 할 수 있습니까?
LINQPad의 코드 편집기를 마우스 오른쪽 단추로 클릭하고 고급 쿼리 속성을 선택하면 추가 참조 및 추가 네임 스페이스 가져 오기라는 두 개의 대화 상자가 있습니다.
1) 추가 참조 에서 추가를 선택한 다음 찾아보기 를 클릭 하고 사용자 지정 어셈블리로 이동합니다.
2) 그런 다음 Additional Namespace Imports 에 해당 어셈블리에서 가져올 네임 스페이스 를 입력합니다 .
LINQPad를 사용하면을 눌러 열 수있는 고급 쿼리 속성 대화 상자를 통해 사용자 지정 어셈블리를 참조 할 수 있습니다 F4.
실제로 Book.linq와 같은 linq 파일을 메모장으로 보면 파일이 XML과 코드 조각이 혼합되어있는 것을 볼 수 있습니다.
<Query Kind="Statements"> <!-- kind: Program, ... --->
<Connection>...</Connection> <!-- Optional, if you have connection to db -->
<Reference>[path]\[library]</Reference> <!-- references to your customized libraries -->
<Reference>RuntimeDirectory>System.Data.dll</Reference> <!-- example to System.Data.dll -->
<Namespace>System.Data</Namespace> <!-- here are nodes for namespaces... -->
<Namespace>MyLibrary.Common</Namespace>
</Query>
var conn = "Data Source=...";
....
In order words, you may find more detail information from example linq files about how LINQPad gets all the information out, builds a dynamic assembly and runs it internally to get results back to its UI.
By the way, I wrote a blog last night about this tool and my understanding of its structure: LINQPad a .Net Snippet Code IDE.
Edward, we used a number of strategies when building the LINQ in Action samples. In the database chapters, we often just relied on LINQPad's ability to autogenerate the classes based on the database tables.
In the case you reference here (4.04) we did add the reference to the pre-compiled class library using F4. We used this strategy in cases where LinqPad generated classes different from those generated by Visual Studio and thus caused the context to behave differently than you would expect, particularly in regards to change tracking.
In other cases, we added a nested class inline with the rest of the sample and used the "Program" option in the code editor. See example 6.02. In this case, we're actually imbedding the Books class inside of the generated DataContext class that LinqPad generates. We also used this strategy when we wanted to alias our column names because the auto-generated classes that LinqPad creates doesn't easily let us alias those columns inside the tool.
In a couple samples, particularly where we are demonstrating custom extension methods, we had to do another trick of forcing the generated context class to finish (adding an aparently unmatched ending } or End Class) and then starting a new class, but omitting it's closing end brace/end class. You can see this in example 2.16 in the downloaded samples.
'IT TIP' 카테고리의 다른 글
| GIT_WORK_TREE는 무엇입니까?이 ENV 변수를 설정할 필요가없는 이유는 무엇입니까? (0) | 2020.11.20 |
|---|---|
| 파이썬 JSON은 첫 번째 수준에서만 키를 얻습니다. (0) | 2020.11.20 |
| Visual Studio : 프로세스가 생성 될 때 프로세스에 자동 연결 (0) | 2020.11.20 |
| 숨겨진 파일을 제외한 파일 목록 가져 오기 (0) | 2020.11.20 |
| 모든 SQL Server 외래 키에 일치하는 인덱스가 있어야합니까? (0) | 2020.11.20 |