103 articles ASP.NET MVC Page 6 / 11

Kendo Stacked Bar Chart with Complex Data

Kendo stacked bar chart dapat menerima berbagai bentuk data untuk menghasilkan chart. Berikut adalah contoh bentuk data yang dapat digunakan untuk kasus yang kompleks. Server mengirimkan List [code language=”csharp”] public class ChartColumnAttribute { public double Value { get; set; } public string Category { get; set; } //RKAP, RKAP s.d. Jun’14, Real s.d. Jun’14, Real…

Linq to SQL Nested Query Where In

Contoh Linq to SQL nested query where in [code language=”sql”] select … from x where x in (select id from …) [/code] [code language=”csharp”] IQueryable<int> innerQuery; //algoritma innerQuery = from log in db.permit_log where log.user_id == UserId && log.permit_type == 0 && (log.status == KPIMaster.SupervisorApprove || log.status == KPIMaster.SupervisorReject) select log.id_permit.Value; var query = from…

Linq to SQL Select inside Join

Berikut contoh query Linq dengan select di dalam join table [code language=”csharp”] int count = ( from permit in db.permit_to_work join log in ( from log in db.permit_log.Where(m => m.permit_type == 0 && m.status == queryStatus && m.user_id == UserId) .GroupBy(m => m.id_permit) select new { id_permit = log.Key, maxdt = log.Max(m => m.datetime) }…

Complex Custom Validation using Validator.TryValidateObject

Contoh fungsi validasi ketika meng-import file excel berisi banyak data manufacturer [code language=”csharp”] [HttpPost] public ActionResult Process(ManufacturerModel model) { if (ModelState.IsValid) { //kamus List<ValidationResult> results = new List<ValidationResult>(); List<string> errList = new List<string>(); List<ManufacturerFormStub> list = model.Parse(); List<ManufacturerCategoryFormStub> listCategory = model.ParseCategory(); manufacturer manufacturer; //algoritma for (int i = 0; i < list.Count; ++i) { results.Clear();…

Entity Framework: The provider did not return a providermanifest instance

In my case I had to hack the .EDMX file and change the ProviderManifestToken=”2008″ Open your Model.edmx in editor Change the ProviderManifestToken=”2012″ to ProviderManifestToken=”2008″ http://stackoverflow.com/questions/19574981/entity-framework-the-provider-did-not-return-a-providermanifest-instance

NPOI Generate Excel with Date Format

Jika kita ingin memasukkan object DateTime ke dalam cell menggunakan NPOI, perlu ada penanganan khusus. [code language=”csharp”] XSSFCellStyle styleDate = (XSSFCellStyle)workbook.CreateCellStyle(); styleDate.DataFormat = workbook.CreateDataFormat().GetFormat("yyyy-mm-dd HH:mm"); XSSFCell cell = (XSSFCell)row.CreateCell(colIndex++); cell.SetCellValue(single.Timestamp); cell.CellStyle = styleDate; [/code] http://stackoverflow.com/questions/3425931/npoi-excel-number-format-not-showing-in-excel-sheet-in-asp-net

The specified type member ‘Date’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties

Fungsi komparasi Date pada Linq dapat menimbulkan error seperti tertulis di judul. Solusinya dengan menggunakan fungsi TruncateTime [code language=”csharp”] var eventsCustom = eventCustomRepository.FindAllEventsCustomByUniqueStudentReference(userDevice.UniqueStudentReference) .Where(x => DbFunctions.TruncateTime(x.DateTimeStart) == currentDate.Date); [/code] http://stackoverflow.com/questions/14601676/the-specified-type-member-date-is-not-supported-in-linq-to-entities-only-init

Unable to determine the principal end of an association between the types Error

Error disebabkan adanya relasi one-to-one antar 2 tabel. Contoh skema: Solusinya, tambahkan line berikut [code language=”csharp”] protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Membership>().HasRequired(a => a.User).WithRequiredPrincipal(b => b.Membership); } [/code] http://stackoverflow.com/questions/21849523/unable-to-determine-the-principal-end-of-an-association-between-the-types-error