Näytetään tekstit, joissa on tunniste ASP.NET MVC. Näytä kaikki tekstit
Näytetään tekstit, joissa on tunniste ASP.NET MVC. Näytä kaikki tekstit

maanantai 7. joulukuuta 2015

torstai 20. elokuuta 2015

ASP.net MVC5 - Redirect and TempData

Milloin käytetään ViewBag, ViewData tai TempData ?

Kun käyttäjä halutaan ohjata Redirect:ä käyttäen sivulta toiselle, on hyvä käyttää apuna TempData.
ViewBag ja ViewData ominaisuudet tyhjenevät eli arvo on Empty sen jälkeen, kun on siirrytty yksi sivu eteenpäin. Jos halutaan palata esim. kaksi sivua taaksepäin, niin TempData:ssa säilyy tieto, jolla käyttäjä voidaan palauttaa.

tiistai 23. kesäkuuta 2015

TortoiseHg - .hgignore

Käytän Visual Studio Community 2013 versiota. Versiohallintana on TortoiseHg.

Kävipä eräänä päivänä, että lähdin muuttamaan .hgignore tiedoston nimeä.. muuttaminen takaisin entiseksi ei sitten onnistunutkaan windowsin tiedostojen hallinnan kautta.
Avuksi tuli tämä ohje.


Käyttämilleni ohjelmaversiolle sopiva .hgignore versiohallintaan on:

############################################################
## Visual Studio 2013
############################################################
syntax: glob

## User-specific files

*.suo
*.user
*.sln.docstates

## Build results

[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
build/
bld/
[Bb]in/
[Oo]bj/

## Roslyn cache directories

*.ide/

## MSTest test Results

[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

## NUnit

*.VisualState.xml
TestResult.xml

## Build Results of an ATL Project

[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

## Chutzpah Test files

_Chutzpah*

## Visual C++ cache files

ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

## Visual Studio profiler

*.psess
*.vsp
*.vspx

## TFS 2012 Local Workspace

$tf/

## Guidance Automation Toolkit

*.gpState

## ReSharper Ignores

_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

## JustCode

.JustCode

## TeamCity Ignores

_TeamCity*

## DotCover Ignores

*.dotCover

## NCrunch Ignores

_NCrunch_*
*.ncrunch*
.*crunch*.local.xml

## MightyMoose
*.mm.*
AutoTest.Net/

## Web workbench (sass)
.sass-cache/

## Installshield output folder

[Ee]xpress/

## DocProject Ignores

DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

## Click-Once Ignores

publish/

## Publish Web Output

*.[Pp]ublish.xml
*.azurePubxml
*.pubxml

## Windows Azure Build Ignores

csx/
*.build.csdef

## Windows Store Ignores

AppPackages/

## RIA/Silverlight projects

Generated_Code/

## SQL Server Ignores

App_Data/*.mdf
App_Data/*.ldf

## Backup & Report Files when converting a solution
## Not required, we have mercurial!

_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

## NuGet
packages/

## Business Intelligence projects

*.rdl.data
*.bim.layout
*.bim_*.settings

## Microsoft Fakes

FakesAssemblies/
*.favdoc

## Miscellaneous Ignores

sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/

## Windows Ignores

$RECYCLE.BIN/
Thumbs.db
ehthumbs.db
Desktop.ini

maanantai 22. kesäkuuta 2015

ASP.NET MVC 5 - Conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

Tässä hyödyllinen linkki päivämäärien käsittelyssä tulevaan virheeseen..

Itse ymmärsin asian lyhyesti sanottuna näin:
SQL server ja .NET käsittelevät DataTime arvoa eri tavoin ja. Jos .NET koodista viedään "tyhjä" päiväys tietokantaan, niin tulee ym. virheilmoitus. Ratkaisu on, että luodaan oletusarvot päivämäärille MVC5.net modelissa:

 public class Offer
    {
        public Offer()
        {
            OfferValid = DateTime.Now;
            ContractStartTime = DateTime.Now;
            ContractEndTime = DateTime.Now;
        }
...
     
        [Display(Name = "OfferValid", ResourceType = typeof(Resources.Resources))]
        public DateTime? OfferValid { get; set; }
[Display(Name = "ContractStartTime", ResourceType = typeof(Resources.Resources))]
        public DateTime? ContractStartTime { get; set; }
        [Display(Name = "ContractEndTime", ResourceType = typeof(Resources.Resources))]
        public DateTime? ContractEndTime { get; set; }

maanantai 6. huhtikuuta 2015

ASP.NET MVC

Dataseppä aloittanut kahdessa uudessa projektissa, jossa ohjelmoinnin työkaluna ASP.NET MVC ja tietokantana SQL Server. Jatkossa blogiin tulee tietoa ja ongelmanratkaisua näihin tekniikoihin liittyen.

perjantai 23. tammikuuta 2015

Mikä on Entity Framework 6 ?



Entity framework 
= object-relational mapper (ORM) framework

To read or update data, you can use ADO.NET directly by using classes such as SqlCommand, SqlDataReader, SqlDataAdapter, and DataSet. The recommended alternative is to let an object-relational mapper (ORM) framework such as the Entity Framework handle the low-level code that interfaces with an ADO.NET data provider. If you use ADO.NET directly, you have to manually write and execute SQL queries. You also have to write code that converts data from the database's format into objects, properties, and collections that you can work with in code.

Suomeksi:
  • koodiin ei tarvitse kirjoittaa SQL:ää ja komentaa ADO.NET:iä, vaan Entity frameworkista löytyy nopeampi tapa toteuttaa tauluun kirjoitus, luku, päivitys yms.
  • vähempi koodia, vähemmän virhemahdollisuuksia  
  • kun koodi käyttää ORM:ää, niin kantojen siirto SQL serveriltä Windows Azure SQL databaseen onnistuu ilman muutoksia  
  • jos tuntuu, että SQL olisi tehokkaampi jossain erikoistapauksessa, niin: see Advanced Entity Framework Scenarios for an MVC Web Application on the ASP.NET site