DEV Community

Discussion on: ORM-less Data Access in .Net Core

Collapse
 
slavius profile image
Slavius

I'm sorry but aren't you giving up what ORM is for?
Portability? Do you like replacing all "SELECT TOP X" by "SELECT ... LIMIT X" when porting from MSSQL to MySQL?

What about security and performance (aka SQL injection and SQL plan caching)? Do you write every query as "
DECLARE @param1 int
DECLARE @param2 varchar(20)
DECLARE @param3 datetime

SELECT first,last,login,password,birthdate,street,city,country
FROM Users
WHERE age >= @param1
AND login = @param2
AND created <= @param3"

instead of "
var result = Users.Where(age >= 30 && login = UserLogin && created >= Datetime.Now(-30)).AsList();"
? Don't you feel you're sacrificing something?

Collapse
 
aerosoul profile image
Daniel Liuzzi

Portability is always the first reason that comes up for using an ORM, and I wonder how often switching DB vendors actually happens in the real world.

Also, when using Dapper you really don't need those DECLAREs as it infers them from the values you pass in.

Lastly, your own example shows the cost of the ORM convenience. For instance, say you only need ID and Name for populating a drop-down list, an ORM will select each and every column in the table, whereas in SQL you can SELECT ID, Name.