私はこのクラスを持っています
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace IVF_EHR.Models
{
public class SemenProcess
{
public Guid SemenProcessID { get; set; }
public virtual List<CollectionMethod> CollectionMethods { get; set; }
public SemenProcess()
{
SemenProcessID = Guid.NewGuid();
CollectionMethods = new List<CollectionMethod>();
}
}
}
ご覧のとおり、このクラスには関係幅がありますこのクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DevExpress.Web.ASPxEditors;
namespace IVF_EHR.Models
{
public class CollectionMethod
{
[Key]
public int CollectionMethodID { get; set; }
[Required]
[MaxLength(50)]
public string Title { get; set; }
public virtual List<SemenProcess> SemenProcesss { get; set; }
public CollectionMethod()
{
CollectionMethodID = 0;
Title = "";
SemenProcesss = new List<SemenProcess>();
}
}
}
この 2 つのクラス間の関係は多対多です。これを行うパフォーマンスの良い1つのlinqクエリを作成する必要があります
select dbo.GetWokeTitle(s.SemenProcessID)[woleTitle] , * from [SemenProcesses] [s]
そしてdbo.GetWokeTitle
こんな感じです
CREATE FUNCTION GetWokeTitle
(
@SemenProcessID uniqueidentifier
)
RETURNS nvarchar(max)
AS
BEGIN
declare @result nvarchar(max)
set @result = '';
select @result = @result + title from [SemenProcessCollectionMethods] [sc] inner join [CollectionMethods] [c] on c.[CollectionMethodID]=sc.[CollectionMethod_CollectionMethodID]
where sc.SemenProcess_SemenProcessID=@SemenProcessID
-- Return the result of the function
RETURN @result
END
GO
私は ADO.NET Entity Framework を使用しており、上記の SQL コードと同じことを行う linq クエリを作成する必要があります。もう1つ、パフォーマンスの問題のために.ToList()を実行できません。そのクエリを実行せずに1つのクエリを生成する必要があります。実際には、オブジェクトリストではなくクエリを使用するコントロールと、クエリを単独で実行するコントロールがあります。私はビューを作成してエンティティでそのビューを使用できますが、何か他のものが必要です。それは最後の方法かもしれません