エンティティ バージョン 4.0 DAL を持つ ASP.NET Web サイトがあります。データを入力できるテキストボックスと、そのデータを表示および編集するためのグリッドビューがあるページがいくつかあります。LINQ を使用して、いずれかのページのコード ビハインド ファイルに挿入ロジックを記述しています。ただし、このコードを複数の場所で使用し、1 つの場所だけを変更できるように、BLL (ビジネス ロジック レイヤー) を実装したいと考えています。とにかく、コードビハインドで特定のテーブルに対してこれらの BLL 関数を呼び出す必要があり、Visual Studio の GUI を使用してそれらを EntityDataSources にアタッチしたいと考えています。カスタム ロジックを記述するために別のクラス ファイルを作成できましたが、GUI を使用して別の更新、挿入、または機能を削除します。BLL の関数を間違ったプロパティで装飾していますか? 以下は、それを機能させるための私の試みです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyTestModel;
/// <summary>
/// Used as custom logic for running queries againts the Location table
/// </summary>
public class LocationBLL
{
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public IQueryable<RnLoc> viewLocation(string name)
{
MyTestEntities db = new MyTestEntities();
var L = (from a in db.Location
where a.Location == name
select a);
return L;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, false)]
public bool InsertLocation(string location, string longName, string comments, bool active, bool current)
{
MyTestEntities db = new MyTestEntities();
Location L = new Location();
L.Location = location;
L.LongName = longName;
L.Comments = comments;
L.Active = active;
L.Current = current;
L.Edited = DateTime.Now;
L.Created = DateTime.Now;
L.EditedBy = "EIC";
L.CreatedBy = "EIC";
L.AreaID = 1;
db.AddToLocations(L);
db.SaveChanges();
return true;
}
}