간만에 포스팅 합니다. 한 오백만년은 된 듯합니다. ㅋㅋㅋ

요즘엔 asp.net 을 가지고 맨땅에 헤딩하느라 고생이 이만 저만이 아니네요... ㅋㅋㅋ
전 winform 개발자이고 싶은데 말이죠... 푸헤헤

여튼 Bug 라고 공식적으로 알려진 사항인데 저는 이제야 알았네요...

내용은 이렇습니다.

Repeater 나 ListView Server Control 의 itemTemplate 에 RadioButton 을 추가하게 되면 grouping 을 할 수 없습니다.

이유인 즉은 iNamingContainer 인터페이스를 구현하는 녀석들이라서라고 하네요.

iNamingContainer 인터페이스의 특징은 item Template 내부에 추가되는 컨트롤들은 고유의 name 속성을 가져야하는 데...

아시다 시피 radio 버튼을 Group으로 묶어 주기 위해서는 아래와 같이 name 속성을 동일하게 해야햐죠?

<input id="Radio1" type="radio" name="1" />
<input id="Radio2" type="radio" name="1" />
<input id="Radio3" type="radio" name="1" />
<input id="Radio4" type="radio" name="1" />
<input id="Radio5" type="radio" name="1" />


그런데 iNamingContainer 인터페이스 를 구현하는 녀석들은 name 속성이 고유하게 생성이 되서 Group 으로 묶이지 않는 것이었습니다.
asp.net RadioButton 서버컨트롤이 가지고 있는 GroupName 이라는 속성을 주더라도 소용이 없는 거죠... ㅋㅋ

아래의 Repeater 나 ListView 가
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <asp:RadioButton id="RadioButton1" runat="server" GroupName="RB" Text="<%#Container.DataItem.ToString()%>">
                </asp:RadioButton><br>
            </ItemTemplate>
        </asp:Repeater>

HTML Tag 로 Rendering 된 모습을 보게되면 아래와 같습니다.
<input id="MainContent_Repeater1_RadioButton1_0" type="radio" name="ctl00$MainContent$Repeater1$ctl00$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_0">Test Value 0</label><br>           
<input id="MainContent_Repeater1_RadioButton1_1" type="radio" name="ctl00$MainContent$Repeater1$ctl01$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_1">Test Value 1</label><br>            
<input id="MainContent_Repeater1_RadioButton1_2" type="radio" name="ctl00$MainContent$Repeater1$ctl02$RB" value="RadioButton1" /><label for="MainContent_Repeater1_RadioButton1_2">Test Value 2</label><br>

name 속성의 값이 모두 다르죠?

이러니 Group 으로 묶을 수 있겠습니까? ㅋㅋㅋ

http://support.microsoft.com/kb/316495/en-us
여기에 버그로 등록이 되어 있네요... 오랜 세월이 흘렀는데도 고쳐지지 않는 것을 보면... 쉽사리 건드리기 힘든 녀석인가 봅니다. 이해가 안가지만요... ㅋㅋ

그래서 해법을 찾아보았습니다. ㅋㅋㅋ

http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/

GroupRadioButton 을 만드신 분도 계시군요...
http://www.codeproject.com/Articles/7960/How-to-group-RadioButtons


행복한 고수되십시요...

저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja

현재 WCF REST Starter Kit Preview 2 을 이용해서 Rest Service 를 제작하여 사용하고 있다.
그런데 문제가 발생했다.
기존에 개발하던 Laptop에서는 잘 작동하던 것이
새로운 Laptop에서는 아래와 같은 씨뻘건 에러를 내뱉으며 작동을 거부하는 것이 아닌가? ㅡㅡ'


어리석게도 단순히 파일 확장자만을 보고 MIME Type 이 문제일 것이라는 생각에만 집중을 하고 문제를 해결하기위해 두 컴을 비교하기 시작했고, 찾다찾다 안되어 구글링을 시작했다.

.svc 파일 형식이 aspnet_isapi 에 매핑되어 있어야 한다는 결론을 얻었다.

그래서 살펴보니 기존 Laptop 에는 등록되어 있는
svc-Integrated
svc-ISAPI-2.0
항목들이 새로운 Laptop 에는 등록되지 않은 것이 아닌가?

훔...
위 항목들의 등록과정은 다음과 같다.

IIS 단에서 등록을 해도 되겠지만 본인은 Default Web Site (기본 웹 사이트) 에서 진행하기로 하겠다.

위와 같이 "처리기 맵핑"을 클릭한다.


그리고 "관리되는 처리기 추가..." 를 클릭하고
요청경로 : *.svc
형식 : System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
이름 : svc-Integrated
을 입력하고 "확인" 을 클릭한다.

 
다음은 "스크립트 매핑 추가..." 를 클릭하고
요청경로 : *.svc
실행파일 : %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
이름 : svc-ISAPI-2.0
을 입력하고 "확인" 을 클릭한다.


그리고 잘 등록이 되었는지 확인한다.


그러면 Browser 로 가서 F5 를 눌러 화면을 Refresh 해서 확인해 본다.


또 이렇게 나의 허접함이 드러났다. ㅡㅡ'


하지만, 아직도 전 Laptop 과 비교해서 새 Laptop 에는 무엇을 설치를 하지 않아
녀석들이 등록되지 않았는지 알수가 없다.

아시는 분께서는 저의 무지함을 깨우쳐 주시기 바랍니다.



행복한 고수되십시요...


woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja

    1 @Code

    2 

    3     Dim myIntNumber = 0

    4     Dim myStringNum = "539"

    5     If myStringNum.IsInt() Then

    6         myIntNumber = myStringNum.AsInt()

    7     End If

    8 

    9 End Code


AsInt(), IsInt()
Dim myIntNumber = 0 
Dim myStringNum = "539" 
If myStringNum.IsInt() Then 
    myIntNumber
= myStringNum.AsInt() 
End If
나머지는 비슷...
AsBool(), IsBool()
AsFloat(), IsFloat()
AsDecimal(), IsDecimal()
AsDateTime(), IsDateTime()
ToString()


행복한 고수되셔요...

woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > Razor' 카테고리의 다른 글

[Razor] Razor Converting Data Type  (0) 2011/04/06
Posted by woojja


Controller들은 Controllers Folder 에,
Java Script 는 Scripts Folder 에,  
MVC View File들은 Views 폴더에 담아야 한다.

행복한 고수되십시요.


woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja

Localization 을 하니라고 Resource 파일을 여러 언어로 맹글었었습니다.
그런데 갑자기 ko (우리나라) 언어만 내용이 싹 사라져버렸습니다.



위 질문으로 구글링을 해봐도 뾰족한 답이 없었습니다.

그러다 알게 되었네요...
답은 Access Modifier 에 있었습니다.

요로케

필요에 따라서는 Public 으로 바꾸어 주셔도 되겠죠...


그러면 아래와 같이... 뾰로롱 생기게 됩니다.



훔...

정책임님 아티클 어딘가에 있을 듯 하지만...
이제서야 떠올리게 되었습니다. (혹시 거기에 있지 않을까?)
그르나 찾았으니... 안찾아 볼랍니다. ^^

그럼 행복한 고수되셔요...

저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > VS' 카테고리의 다른 글

[VS] How Can I Rebuild resx files?  (0) 2011/03/08
Posted by woojja
아래글 보시기 전에 정책임님의 글을 먼저 보시는 편이 나을듯하여
맨위에 추가적으루다가 적습니다.

Microsoft .NET Framework 2.0 Configuration 수동 설치
; http://www.sysnet.pe.kr/2/0/223




Windows 2008 Server  에서  .NET Framework Configuration 도구를 찾을 수 없는 사태가 발생했습니다.
ㅡㅡ'

현재 Windows 2008 Server 에서 VisualStudio 2008 루다가 개발을 진행중에 있는데요...
보안 정책을 설정, 배포 해야할일이 있어서 찾아 보게되었는데...
이게 왠걸... ㅡㅡ'

당연히 있을 거라 생각했던 녀석이 없는 것이 아니겠습니까? ㅡㅡ'

구글링 결과
이 녀석을 다운 받아서 설치하라는 군요..

Windows SDK for Windows Server 2008 and .NET Framework 3.5

아래는 설치 화면 모습입니다.








그러나 !!! ㅡㅡ'

나타나지 않더라는...
한마디로 그 긴시간동안 헛짓, 뻘짓, 삽질했다는... ㅡㅡ'

그래서 찾아다니다...
한 사이트를 찾았습니다.
http://www.technowise.in/2009/03/net-framework-20-configuration-tool.html

Configuration Tool 만 설치해주는... ㅡㅡ'




이제야 나타났군요...
아주 작은 것에 기뻐하는... ^^'

위 사이트페이지에 가시면 받으실 수 있지만...
저도 휘리릭... 링크걸어봅니다.

.NET Framework configuration tool installer(MSI)


이제 할 걸 해봐야겠습니다. ^^

행복한 고수되십시요...
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja
VisualBasic 은 그냥 프로퍼티 하나 추가해주면 되는 것을...
C# 은 쩝...

VB 는 아래와 같이 설정하지요...


갑자기 구현을 해야할 것이 생겨서요 찾아보다가
다음 페이지를 참고해서? ㅡㅡ' (베껴서 작성했습니다.)


덕분에 금새 만들었습니다요... ㅡㅡ'

보실 분들 참고 하셔요...
http://ko.w3support.net/index.php?db=so&id=391339

    4     static class Program

    5     {

    6         /// <summary>

    7         /// 해당 응용 프로그램의 주 진입점입니다.

    8         /// </summary>

    9         [STAThread]

   10         static void Main()

   11         {

   12             if (!IsAppAlreadyRunning())

   13             {

   14                 Application.EnableVisualStyles();

   15                 Application.SetCompatibleTextRenderingDefault(false);

   16                 Application.Run(new frmUserSynch());

   17             }

   18             else

   19             {

   20                 MessageBox.Show("Application 이 이미 실행중입니다!!!\n작업관리자의 Process 를 확인해 보시기 바랍니다.");

   21             }

   22         }

   23 

   24         private static bool IsAppAlreadyRunning()

   25         {

   26             System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();

   27             return (IsAppAlreadyRunning(currentProcess.Id, currentProcess.ProcessName));

   28         }

   29 

   30         private static bool IsAppAlreadyRunning(int ID, string Name)

   31         {

   32             bool isAlreadyRunnig = false;

   33 

   34             System.Diagnostics.Process[] processess = System.Diagnostics.Process.GetProcesses();

   35 

   36             foreach (System.Diagnostics.Process process in processess)

   37             {

   38                 if (ID != process.Id)

   39                 {

   40                     if (Name == process.ProcessName)

   41                     {

   42                         isAlreadyRunnig = true;

   43                         break;

   44                     }

   45                 }

   46             }

   47             return isAlreadyRunnig;

   48         }

   49     }


그럼 행복한 고수되셔요...

저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > C#' 카테고리의 다른 글

[C#] 단일 Process 실행  (2) 2010/11/08
[C#] C# 은 VB.NET 따라쟁이...  (3) 2009/05/07
[C#] C# 컴파일러 오류  (0) 2009/03/06
[C#] 요것 한번 보시죠... VB.NET 에는 없어요. ^^'  (0) 2009/03/06
[C#] Yield  (0) 2009/03/06
Posted by woojja

 

IIS 7 에서 URL Rewrite Module 을 사용해 보셔요...
재미나네요... ^^

http://www.iis.net/download/urlrewrite

아래 비디오를 통해서 설정하는 방법도 배워보시구요...

http://learn.iis.net/page.aspx/506/url-rewrite-module---video-walkthrough/


아~~ 또 한가지... IIS Extention 들을 찬찬히 살펴보시고
사용하실만한 것들을 설치하셔서 사용해 보십시요...


행복한 고수되셔요...


woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (1)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (2)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (3)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (4)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (5)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (6)
이번엔 Controller  와 View  를 만들어 보겠습니다.
그림을 그냥 쭉 훑어 보시기만 해도 될 듯합니다.
Solution 탐색기의 Context Menu 도 직관적으로 구성되어 있어서 생성하기도 쉽고요...
그럼 Controller  부터 시작해 보겠습니다.

Controller Folder 를 오른쪽 클릭합니다.


Add/Controller... 를 클릭하여 Controller 를 추가합니다.
새로 만들어질 Controller  의 이름을 입력합니다.
Action Method 를 생성하진 않을 겁니다.

만들어진 Controller 의 내용을 아래와 같이 index 함수와 info 함수를 입력합니다.

    1 Namespace MvcSampleApp

    2 

    3     Public Class CustomerController

    4         Inherits System.Web.Mvc.Controller

    5         Private repository As New AdventureWorksRepository()

    6 

    7         '

    8         ' GET: /Customer

    9 

   10         Function Index() As ActionResult

   11             Return View()

   12         End Function

   13 

   14         Public Function Index(ByVal page As Nullable(Of Integer)) As ActionResult

   15             Dim viewData = New CustomerViewData()

   16             Dim currentPage As Integer = If(page, 0)

   17             viewData.Customers = Me.repository.GetCustomers(currentPage, 10)

   18             viewData.NextPage = currentPage + 1

   19             viewData.PreviousPage = If((currentPage <= 0), 0, currentPage - 1)

   20             Return View(viewData)

   21         End Function

   22 

   23         Public Function Info(ByVal id As Integer) As ActionResult

   24             Dim customer = Me.repository.GetCustomerById(id)

   25             Return View(customer)

   26         End Function

   27 

   28     End Class

   29 

   30 End Namespace


Controller 하나 더 만들어 보죠.
이번엔 Action Method  도 만들어 보죠.


아래와 같은 함수가 기본적으로 만들어질텐데요...
기본적으로 만들어진 함수를 아래와 같이 수정합니다.

    1 Namespace MvcSampleApp

    2 

    3     Public Class AddressController

    4         Inherits System.Web.Mvc.Controller

    5         Private repository As New AdventureWorksRepository()

    6 

    7         '

    8         ' GET: /Address/Create/5

    9         Function Create(ByVal customerId As Integer) As ActionResult

   10             Dim addressViewData = New AddressViewData With

   11                 {

   12                     .CustomerId = customerId

   13                 }

   14             Return View(addressViewData)

   15         End Function

   16 

   17         '

   18         ' POST: /Address/Create

   19         <AcceptVerbs(HttpVerbs.Post)> _

   20         Function Create(ByVal customerId As Integer, ByVal collection As FormCollection) As ActionResult

   21             Try

   22                 Dim addressViewData = New AddressViewData()

   23                 UpdateModel(addressViewData)

   24                 Me.repository.AddAddress(addressViewData.Address, customerId)

   25                 Return RedirectToAction("Info", "Customer", New With {.id = customerId})

   26             Catch

   27                 Return View()

   28             End Try

   29         End Function

   30 

   31         '

   32         ' GET: /Address/Edit/5

   33         Public Function Edit(ByVal addressId As Integer, ByVal customerId As Integer) As ActionResult

   34             Dim addressViewData As New AddressViewData()

   35             addressViewData.Address = Me.repository.GetAddressById(addressId)

   36             addressViewData.CustomerId = customerId

   37             Return View(addressViewData)

   38         End Function

   39 

   40         '

   41         ' POST: /Address/Edit/5

   42         <AcceptVerbs(HttpVerbs.Post)> _

   43         Public Function Edit(ByVal addressId As Integer, ByVal customerId As Integer, ByVal collection As FormCollection) As ActionResult

   44             Try

   45                 Dim addressViewData As New AddressViewData()

   46                 addressViewData.Address = Me.repository.GetAddressById(addressId)

   47                 UpdateModel(addressViewData)

   48                 Me.repository.UpdateAddress()

   49                 Return RedirectToAction("Info", "Customer", New With {.id = customerId})

   50             Catch

   51                 Return View()

   52             End Try

   53         End Function

   54 

   55         '

   56         ' POST: /Address/Edit/5

   57         <HttpPost()> _

   58         Function Edit(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult

   59             Try

   60                 ' TODO: Add update logic here

   61 

   62                 Return RedirectToAction("Index")

   63             Catch

   64                 Return View()

   65             End Try

   66         End Function

   67 

   68         '

   69         ' GET: /Address/Delete/5

   70         Public Function Delete(ByVal addressId As Integer, ByVal customerId As Integer) As ActionResult

   71             Dim address = Me.repository.GetAddressById(addressId)

   72             Me.repository.DeleteAddress(address, customerId)

   73             Return RedirectToAction("Info", "Customer", New With {.id = customerId})

   74         End Function

   75 

   76         '

   77         ' POST: /Address/Delete/5

   78         <HttpPost()> _

   79         Function Delete(ByVal id As Integer, ByVal collection As FormCollection) As ActionResult

   80             Try

   81                 ' TODO: Add delete logic here

   82 

   83                 Return RedirectToAction("Index")

   84             Catch

   85                 Return View()

   86             End Try

   87         End Function

   88     End Class

   89 

   90 End Namespace


이젠 방금전에 만든 CustomerController 의 info 함수에 연결할 View 를 생성할겁니다.
함수상에서 오른쪽 클릭을 하면 나타나는 Context Menu 에서 "Add View..." 를 클릭합니다.
참 쉽죠~~잉? ^^


ComboBox 에서 DataClass를 입력합니다.



만들어진 View 를 아래와 같이 수정합니다.

   40 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

   41     <h2>

   42         Customer Information</h2>

   43     <fieldset>

   44         <p>

   45             CompanyName:

   46             <%= Html.Encode(Model.CompanyName) %>

   47         </p>

   48         <p>

   49             EmailAddress:

   50             <%= Html.Encode(Model.EmailAddress) %>

   51         </p>

   52         <p>

   53             Name:

   54             <%= Html.Encode(Model.Title + " " + Model.FirstName + " " + Model.MiddleName + Model.LastName) %>

   55         </p>

   56         <p>

   57             Phone:

   58             <%= Html.Encode(Model.Phone) %>

   59         </p>

   60     </fieldset>

   61         <h3>

   62         Addresses</h3>

   63     <ul>

   64         <% For Each address In Model.CustomerAddress%>

   65         <li>

   66             <%= address.Address.AddressLine1 + " " + address.Address.AddressLine2 + " - " + address.Address.City %>

   67             <%= Html.ActionLink("(Edit)", "Edit", "Address", New With {address.AddressID, Model.CustomerID}, Nothing)%>

   68             <%= Html.ActionLink("(Delete)", "Delete", "Address", New With {address.AddressID, Model.CustomerID}, Nothing)%>

   69         </li>

   70         <% Next%>

   71     </ul>

   72     <%= Html.ActionLink("Add New Address", "Create", "Address", New With {Model.CustomerID}, Nothing)%>

   73 

   74 </asp:Content>

   75 


CustomerController 와 AddressController 에 포함되어있는 ActionMethod 에 대한 View 를 같은 방식으로 만듭니다.
그 내용은 유사하므로 이곳에 설명하진 않습니다.


F5 를 클릭해서 Web Application을 실행해 봅니다.

Customer 링크를 클릭해서 리스트를 확인하고...
Page 를 이동해 봅니다.
Address 추가도 해보고...

수정/삭제도 해봅니다.


너무 쉬운내용을 어렵게(설명한답시고 캡쳐하고, 주저리주저리) 풀어 놓은것 아닌가 합니다.
어느정도 MVC2 Application 을 작성하는 방식에 대해서 살펴보았습니다.

기본적으로 구성하는 것. 한마디로 참 쉽죠~~잉... ^^'
허지만 세상일이란 기본적인것만 있지 않죠... ㅋㅋ

여튼 이후에는 이 이외에 Unit Test 를 설정하고, Area 를 구성하는 것도 살펴보려합니다.
자세한 사항에 대해서 살펴보기전까지는 기본 구성에 대해서만 진행할려구요...

 
행복한 고수되십시요.


woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (1)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (2)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (3)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (4)
[.NET/ASP.NET] - [ASP.NET] ASP.NET MVC2 Site 만들기 (5)

지난번까지는 ASP.NET MVC2 Application 구성에 대해서 간단하게 살펴보았습니다.
그리고 MVC Application 을 생성했을때 기본적으로 만들어지는 파일들로 Build 까지 해 보았습니다.

이번 부터는 본격적으로 Application 을 만들어 나가려고 하는데요.
지난 아티클에서 만든 기본적인 Web Application 을 바탕으로 이어 나가려고 합니다.

고객들의 List 를 뿌려보고요. 고객 정보를 조회하고 고객의 주소를 생성, 수정, 삭제하는 코드를 작성해 보도록 하겠습니다. 

다음 세 개의 Controller 를 작성할 것입니다. 고객 리스트, 고객정보를 다루는 Controller, 주소를 생성, 수정, 삭제하는 Address Controller 와 마지막으로 Application 의 환영 Page View를 다루는 Home Controller 입니다. 

음 그럼 먼저 master 파일을 아래의 Source 로 변경합니다.

    1 <%@ Master Language="VB" Inherits="System.Web.Mvc.ViewMasterPage" %>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    4 <html xmlns="http://www.w3.org/1999/xhtml">

    5 <head runat="server">

    6     <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>

    7     <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

    8 </head>

    9 

   10 

   11 <body>

   12     <div class="page">

   13 

   14         <div id="header">

   15             <div id="logo">

   16                     <h1>My MVC Application</h1>

   17             </div>           

   18             <ul id="menu">

   19                 <li>

   20                     <%= Html.ActionLink("Home", "Index", "Home")%>

   21                 </li>

   22                 <li>

   23                     <%= Html.ActionLink("About Us", "About", "Home")%>

   24                 </li>

   25                 <li>

   26                     <%= Html.ActionLink("Customers", "Index", "Customer") %>

   27                 </li>

   28             </ul>

   29         </div>

   30 

   31         <div id="main">

   32             <div id="content">

   33 

   34                 <asp:ContentPlaceHolder ID="MainContent" runat="server" />

   35 

   36             </div>

   37             <div id="footer">

   38                 <p>

   39                     My Sample MVC Application &copy; Copyright 2009

   40                 </p>

   41             </div>

   42         </div>

   43 

   44     </div>

   45 </body>

   46 </html>


그럼 EDM (Entity Data Model) 을 사용하는 것으로부터 시작하겠습니다.

AdventureWorks Entity Data Model 을 추가하도록 하겠습니다.
Models 폴더를 오른쪽 클릭해서 Entity Data Model 을 생성합니다.

파일명은 AdventureWorks.edmx 입니다. 

선택을 하게되면 Entity Data Model Wizard 가 열립니다.
"Generate from database" 항목을 선택합니다.
Connection 정보가 없군요.
그럼 생성을 해 줘야겠죠. "New Connection..." 버튼을 클릭해 줍니다.

SQL Server 를 선택해 주고요. "Continue" 버튼을 클릭합니다.

서버를 선택할 수 있는 창이 뜹니다.
서버를 선택하고 Database 를 선택한 후 연결상태를 테스트 합니다.
그리고 "OK" 버튼을 꾹 눌러주면...

선택한 사항에 대한 내용이 채워져 있습니다.
Connection String 에 대해서는 한번 살펴보셔도 좋을 듯 합니다.
Wizard 를 사용해서 뿐만이 아니라 직접 코딩할때도 쓸수 있을 테니 말이죠.
그리고 Checkbox 의 내용을 보면 Textbox 에 적혀진 이름으로 Web.config 파일에 ConnectionString 정보를 저장하겠느냐 라는 옵션을 달아 놨습니다.
Web.config 파일을 확인해 보셔도 좋을 듯 합니다.

Database 를 선택했으니 사용하려는 Table 을 선택해야겠지요?

과정을 모두 마치게 되면 아래와 같이 Entity Model 이 생성됩니다.
이 파일을 직접 별도의 Text Editor 로 열어보십시요. Address, CustomerAddress, Customer Class 가 만들어 진것을 확인 하실수 있습니다.

이번엔 AdventureWorksRepository 라는 Repository Class 를 생성할 텐데요... 이 Repository 라는 녀석은 방금 생성한 Model 의 Entity 들을 검색하기위한 Mehtod 를 노출하는 역할을 합니다.


아래는 AdventureWorksRepository.vb 파일의 코드입니다.

    1 Public Class AdventureWorksRepository

    2     Private context As New AdventureWorksLT2008R2Entities()

    3 

    4     Public Function GetCustomers(ByVal page As Integer, ByVal size As Integer) As IEnumerable(Of Customer)

    5         Return context.Customer.OrderBy(Function(c) c.CustomerID).Skip(page * size).Take(size)

    6     End Function

    7 

    8     Public Function GetCustomerById(ByVal customerId As Integer) As Customer

    9         Return context.Customer.Include("CustomerAddress.Address").Where(Function(c) c.CustomerID = customerId).First()

   10     End Function

   11 

   12     Public Sub AddAddress(ByVal address As Address, ByVal customerId As Integer)

   13         address.rowguid = Guid.NewGuid()

   14         address.ModifiedDate = DateTime.Now

   15         context.AddObject("Address", address)

   16 

   17         Dim customerAddress As New CustomerAddress()

   18         customerAddress.Address = address

   19         customerAddress.Customer = GetCustomerById(customerId)

   20         customerAddress.rowguid = Guid.NewGuid()

   21         customerAddress.AddressType = "Shipping"

   22         customerAddress.ModifiedDate = DateTime.Today

   23         context.AddObject("CustomerAddress", customerAddress)

   24         context.SaveChanges()

   25     End Sub

   26 

   27     Public Sub UpdateAddress()

   28         context.SaveChanges()

   29     End Sub

   30 

   31     Public Sub DeleteAddress(ByVal address As Address, ByVal customerId As Integer)

   32         Dim customerAddress As CustomerAddress = GetCustomerAddressById(address.AddressID, customerId)

   33         context.DeleteObject(address)

   34         context.DeleteObject(customerAddress)

   35         context.SaveChanges()

   36     End Sub

   37 

   38     Public Function GetAddressById(ByVal addressId As Integer) As Address

   39         Return context.Address.Where(Function(a) a.AddressID = addressId).First()

   40     End Function

   41 

   42     Public Function GetCustomerAddressById(ByVal addressId As Integer, ByVal customerId As Integer) As CustomerAddress

   43         Return context.CustomerAddress.Where(Function(a) a.AddressID = addressId AndAlso a.CustomerID = customerId).First()

   44     End Function

   45 End Class


다음으로는 CustomerController 가 고객 List 를 표시하는데 사용할 ViewData 를 생성할 것입니다.
ViewData 파일들을 저장할 ViewData 폴더를 생성해 줍니다.


CustomerViewData Class 를 생성해줍니다.


다음은 CustomerViewData Class 의 내용입니다.

    1 Public Class CustomerViewData

    2     Public Property Customers As IEnumerable(Of Customer)

    3     Public Property PreviousPage As Integer

    4     Public Property NextPage As Integer

    5 End Class


다음은 AddressController 가 사용할 ViewData를 생성할 것입니다.

다음은 AddressViewData Class 의 내용입니다.

    1 Public Class AddressViewData

    2     Public Property Address As Address

    3     Public Property CustomerId As Integer

    4 End Class


생각외로 이미지를 Capture 를 하면서 설명을 하다보니 내용은 별개 없는데 엄청 기네요...
이렇게 해야하나 싶기도 한데... ㅡㅡ'
그래도 한번은 끝까지 해보려 합니다.

오늘은 Entity Data Model 을 생성하는 방법을 살펴봤구요.
Entity Data Model 이 Entity 를 노출하기위한 Repository Class 를 생성했습니다.
그리고 Controller 가 사용할 ViewData 까지 생성해 보았습니다.

다음은 오늘 생성한 것들을 바탕으로 본격적으루다가 Controller 들과 View 들을 생성해 보겠습니다.


행복한 고수되십시요...

woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\
저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by woojja
이전버튼 1 2 3 4 5 ... 8 이전버튼