Click here to Skip to main content
15,178,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I'm now learning about entity framework. Most of my sql queries are raw sql queries. I was advised to use entity framework instead and I want to convert every raw sql query that i have into entity framework.

Now, i wanted to know how to insert,update and delete using entity framework in asp.net. My question is, what is the equivalent entity framework query of the following raw sql queries that i have provided below? Also is there sql parameters in entity framework?

1.) "DELETE S FROM stringInstrumentItem S JOIN brand B ON S.brandId = B.brandId WHERE B.name = @brand"

2.) "UPDATE [brand] SET type = @type, name = @name, image = @image WHERE brandId = @brandId"

3.) "UPDATE SII SET SII.brandId = b.brandId FROM stringInstrumentItem SII inner join brand b ON SII.brandId = b.brandId AND b.name = @newName"

4.) "INSERT INTO brand VALUES (@brandId,@type,@name,@image)"

What I have tried:

As of now, i am able to convert the regular select statement that we use like this:

SELECT * from brand

into this:

list = (from g in obj.brands select g).ToList();
Posted
Updated 12-Jul-17 20:33pm
Comments
Maciej Los 13-Jul-17 4:19am
   
Download LinqPad. There's functionality to convert SQL query(ies) into Linq(EF) queri(ies).

   
Ideally you would like to use LINQ for queries, however, there are situations where you need to run raw SQL queries even that is possible with entity framework.

Take a look at [^]

For CRUD operations using entity framework, refer [^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900