본문 바로가기

개발67

Entity Framework에서 MySQL 접속하기 0. Install-Package EntityFramework Entity Framework가 인스톨 되어 있지 않았을 경우엔 EntityFramework 6.0 을 설치합니다. 1. MySQL for Visual Studio를 설치 「mysql-for-visualstudio-2.0.5.msi」 Download MySQL for Visual Studio https://dev.mysql.com/downloads/windows/visualstudio/2.0.html 2. MySQL connector를 설치 「mysql-connector-net-6.9.11.msi」 다운로드 미러 http://mirror.cogentco.com/pub/mysql/MySQLInstaller/ 3. NuGet 패키지 관리에서 My.. 2019. 1. 23.
ASP.NET MVC : CSV 파일을 작성해서 다운로드 하기 ASP.NET MVC에서 CSV 파일을 다운로드 할 경우의 샘플 코드입니다. test.cshtml CSVダウンロード test.js $('.btnCsvDownloadList').click(function () { var documentUrl = document.URL; var baseUrl = documentUrl.substring(0, documentUrl.indexOf('currentPageName')); // baseUrl : 호출할 Controller까지의 url을 추출한 내용. url이 가변성일 경우를 전제로 한다. var mySiteUrl = 'http://mysite.com' // mySiteUrl : 고정 url이 있을 경우엔 고정치를 설정. location.href = mySiteUrl +.. 2019. 1. 23.
Entity Framework에서 제일 최근에 갱신된 레코드를 추출하기 Entity Framework에서 제일 최근에 갱신된 레코드를 추출하는 방법을 정리해 보았습니다. DB샘플 tb1 Id DetailId LastUpdatedAt 1 101 2017-02-01 01:00:00 2 102 2017-02-01 10:00:00 3 103 2017-02-02 01:00:00 4 104 2017-02-01 01:00:00 5 105 2017-02-02 01:00:00 tb2 DetailId Name 101 Name1 102 Name2 예시1. tb1에서 같은 DetailId를 가진 복수의 레코드 중에서 제일 최근에 갱신된 레코드를 추출 var list = (from t in db.tb1 group t by t.DetailId into g select g.OrderByDescendi.. 2019. 1. 23.
Entity Framework에서 SQL문을 직접 실행해서 결과 취득하기 SQL쿼리를 그대로 Entity Framework에서 실행하고 싶을 경우의 사용법입니다. SELECT var testList = new List(); var test = DbContext.Database.SqlQuery("SELECT item_id, details FROM item WHERE item_type = 1;"); if (test != null) { testList = test.ToList(); } INSERT/UPDATE int updateResultCount = DbContext.Database.ExecuteSqlCommand("UPDATE item SET item_type = '2' WHERE item_id = 11;"); SQL -> IQueryable string sql = "SELEC.. 2019. 1. 23.
개인적으로 자주 쓰는 LINQ 샘플 자주 사용하는 내용을 위주로 정리해 보았습니다. 상시 갱신 예정. 1. LINQ로 간단히 데이터를 추출할 경우 Model Sample Model // List testList = new List(); public class TestModel { public int Id { get; set; } public string Name { get; set; } public int Quantity { get; set; } public decimal Price { get; set; } public string Remarks { get; set; } } // List testSubList = new List(); public class TestSubModel { public int Id { get; set; } pub.. 2019. 1. 23.
Visual Studio 2017 의 서식 지정 C#의 서식 설정은 아래 메뉴에서 설정 가능합니다. [Tools] > [Options] > [Text Editor] > [C#] > [Code Style] > [Formatting] 2019. 1. 23.
Visual Studio extension [CodeMaid](코드 정리 툴) CodeMaid Visual Studio의 확장기능으로 코딩의 클린업 및 단순화를 지원합니다. 공식 사이트 CodeMaid | An open source visual studio extension to cleanup, dig through and simplify our code http://www.codemaid.net/ 다운로드 CodeMaid - Visual Studio Marketplace https://marketplace.visualstudio.com/items?itemName=SteveCadwallader.CodeMaid 확장기능을 인스톨 하면 Visual Studio에 [CodeMaid] 메뉴가 추가됩니다. [CodeMaid]내의 [Configuration]에서 상세 설정을 변경 하는 것도 .. 2019. 1. 23.
Ajax처리를 포함한 return false에서 골탕먹은 일 내가 하고 싶었던 것 submit 버튼을 누르면 어떤 조건일 경우에 ajax처리를 하고 나서(여기선 밸리데이션 처리) 결과에 따라 return false;로 submit처리를 중단시키고 싶었습니다. NG 그래서 처음엔 아래와 같은 코드를 썼지만 이 코드는 return false;가 안먹고 그대로 submit 처리가 되어 버렸습니다… 음?;; $('button[type=submit]').click(function () { if ($('#value').length > 0) { $.ajax({ url: '/CheckValue', type: 'POST', async: false, traditional: true, data: { value: $('#value').val() }, success: function (.. 2019. 1. 23.
CSV 파일 출력시에 마지막 행에 NULL 문자열이 삽입되는 문제(byte[] 변환 문제) CSV 파일 작성 기능을 코딩중에 일어난 문제입니다. stream을 byte[]로 변환시킬때 GetBuffer()를 사용할 경우 return stream.GetBuffer(); 제일 마지막 행에 NULL 문자열이 추가되어 있다!? Why do I have a million null characters at the end of my CSV file https://stackoverflow.com/questions/27268994/why-do-i-have-a-million-null-characters-at-the-end-of-my-csv-file?answertab=active#tab-top 조사해 보니 GetBuffer()를 쓰지말고 ToArray()를 사용하라는 답변을 발견했습니다. 이유인 즉슨 GetBuf.. 2019. 1. 23.