Tag: sql to linq conversion

如何在LINQ中在单个连接中的多个字段上进行左连接

我正在尝试对LINQ执行这个简单的SQL查询。 但它给我错误。 这是需要转换为LINQ的SQL查询 DECLARE @groupID int SET @groupID = 2 SELECT * FROM dbo.Person p LEFT JOIN dbo.PersonGroup pg ON ( p.PersonID = pg.PersonID AND pg.GroupID = @groupID) 忽略@groupID。 它将作为LINQ查询的函数参数提供。 这是我试过的LINQ查询。 from p in Person join pg in PersonGroup on new { p.PersonID, groupID } equals new { pg.PersonID, pg.GroupID } into t from rt […]

检查数据库记录映射中的空值

如何检查附加代码中的db null值? 请理解我是一个新的C#转换… 此代码的作用是获取IDataReader对象并将其转换并映射到强类型的对象列表。 但我发现,当读取器中返回空列时,它完全出错。 变流器 internal class Converter where T : new() { // Declare our _converter delegate readonly Func _converter; // Declare our internal dataReader readonly IDataReader dataReader; // Build our mapping based on the properties in the class/type we’ve passed in to the class private Func GetMapFunc() { // declare our field […]

将带有join的SQL查询转换为lambda表达式

不知道如何将以下sql转换为lambda表达式。 我的数据库使用参照完整性和与Content_Training表相关的表内容,具有1对多的关系(1个内容可以包含许多content_trainings) select c.ContentId, c.Name, ct.TrainingTypeId from dbo.Content c left join dbo.Content_Training ct on c.ContentId = ct.ContentId where c.PublishDate is not null order by ct.TrainingTypeId, c.Name

将SQL转换为Linq查询

我对Linq查询很新,我只是想将我的数据库查询转换为Linq。 这是我简单的SQL查询: var query = “SELECT EnrollmentDate, COUNT(*) AS StudentCount ” + “FROM Person ” + “WHERE EnrollmentDate IS NOT NULL ” + “GROUP BY EnrollmentDate”; var data = db.Database.SqlQuery(query); 它运行正常,但是怎么可能在Linq中编写这个查询 ,我只是无法将group by语句转换为Linq。 转换为Linq似乎有些棘手。 谁能帮我这个?

Linq联盟用法?

SQL: SELECT date,total_usage_T1 as TotalUsageValue,’T1′ as UsageType FROM TblSayacOkumalari UNION ALL SELECT date,total_usage_T2 as TotalUsageValue,’T2′ as UsageType FROM TblSayacOkumalari 我尝试将其转换为linq IEnumerable sayac_okumalari = entity.TblSayacOkumalari .Select(x => new { x.date, x.total_usage_T1 }) .Union(entity.TblSayacOkumalari.Select(x => new { x.date, x.total_usage_T2 })); 但我不知道如何将’T1′ as UsageType转换’T1′ as UsageType转换为linq。 我的工会使用也是不正确的。 我的表字段如下: | date | total_usage_T1 | total_usage_T2 | | 2010 | […]