本文介绍了将原始SQL查询转换为实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我现在正在学习实体框架。我的大多数SQL查询都是原始的SQL查询。我被建议使用实体框架,我想将我拥有的每个原始sql查询转换为实体框架。



现在,我想知道如何在asp.net中使用实体框架插入,更新和删除。我的问题是,我在下面提供的以下原始SQL查询的等效实体框架查询是什么?实体框架中还有sql参数吗?



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



2.)UPDATE [品牌] SET类型= @type,name = @ name,image = @image WHERE brandId = @brandId



3.)UPDATE SII SET SII.brandId = b.brandId FROM stringInstrumentItem SII内部联接品牌b ON SII.brandId = b.brandId AND b.name = @newName



4.)INSERT INTO品牌价值(@ brandId,@ type,@ name,@ image)



我尝试了什么:



截至目前,我能够转换我们使用的常规选择语句这个:



SELECT *来自品牌



到此:



list =(从ob在obj.brands中选择g).ToList();

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();

推荐答案



这篇关于将原始SQL查询转换为实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:39