0

Subsonic with Astoria のプレビュー 2 について説明しているインターネット上のリソースがいくつかあります。

http://theruntime.com/blogs/jaykimble/archive/2008/11/18/quotsubsonicquot-for-services-found-subsonic-3--ado.net-data-services.aspx

での作業サンプル

http://code.msdn.microsoft.com/SubSonicForADONETDS

subsonic tt(s) にそれぞれの変更をすべて適用しましたが、MSDN プロジェクトを機能させることができませんでした。除去後:

a) Astoria は QuerySurface.tt の private DB() { } が気に入らなかったので、やみくもにコンストラクターを public にしました

b) 複合主キーの生成方法がわからない

<# if(EnableForUseWIthAstoria) {
#> [System.Data.Services.Common.DataServiceKey("<#=pk#>")] <# }#> 

結果は

[System.Data.Services.Common.DataServiceKey("")] 

それ以外の

[System.Data.Services.Common.DataServiceKey("OrderID", "ProductID")] 

そのため、テーブルを除外しました。

現在の障害

        var q = from cust in ctx.Customers
                where cust.CustomerID == "ROMEY"
                select cust;

        Customers c = q.First();

例外が発生します: セグメント 'Customers' のリソースが見つかりません

誰かがそれを試したことがありますか、または別の最新かつ最高のサンプルの存在を知っていますか?

4

4 に答える 4

1

データ サービスのデモ テンプレートについては、次の問題を参照してください。

http://code.google.com/p/subsonicthree/issues/detail?id=53

于 2009-05-29T04:28:14.013 に答える
0

はい、IUpdatableインターフェイスを使用してss3のバージョンをチェックインし、UpdatableDatabaseクラスからDBクエリサーフェスクラスを継承しました。そのためのスターターテストプロジェクトも含めました。良い点は、URIを使用してDBクラスを構築し、サービスに対して作業を開始できることです。ただし、これは現在のコアの一部ではありません。新しいクラスといくつかの再配置に加えて、テンプレートのマイナーな変更が必要です。これは、人々が以前の仕事に基づいて構築するのではなく、このことを再発明し続ける分野の1つだと思います。プロジェクトに取り入れたいと思った変更がいくつかありますが、実行時に複数のデータベースをセットアップしたり、ado.netサービスなど、変更を加えていません。自分のバージョンを永続的に分岐する必要があると思います。

この問題には、UpdatableDatabaseクラスを示す添付ファイルがあります。

私はこれをに追加しましたSubSonicClasses.ttinclude

public string PrimaryKey
{
    get { return Utilities.CleanUp(this.Schema.GetTablePrimaryKey(TableSchema, TableNameRaw)); }
}

...

[System.Data.Services.Common.DataServiceKey("<#=PrimaryKey #>")]

NorthwindでOrderDetailsをだまし、ファイルを直接編集して2番目のキーを追加したようです。あなたは簡単にこのようなメソッドを書くことができますDatabaseSchema.ttinclude

public string[] GetTablePrimaryKeys(string tableSchema, string tableName)

正しい文字列を作成します。

于 2009-05-27T07:01:34.150 に答える
0

これは、IUpdatable インターフェイスと必要なテンプレートの変更に対するパッチです。これが最終的なプロジェクトに入らないことは 99% 確信していますが、少なくとも私がどのようにそれを行ったかを見ることができます。

http://code.google.com/p/subsonicthree/issues/detail?id=52

于 2009-05-27T19:11:06.390 に答える
0

亜音速ライセンスが関係しているため、ソリューションを圧縮して配布できるかどうかはわかりません。適切な亜音速ではなく、約 2 か月前のものです (期限切れ)。プロジェクトを実行して、まだ機能していることをテストしました。これを行う手順は次のとおりです。

上記の UpdatableDatabase クラスを使用します。それからDBを派生させます(これをテンプレートに入れます):

パブリック部分クラス DB : UpdateableDatabase

UpdatableDatabase.cs は、生成されたクラスに含まれている必要があります。そうしないと、テーブル クラスで GetType() が必要になるため、機能しません。

このサービスは、次のクラスを持つ単なるサービス プロジェクトです。

using System.Data.Services;
using Northwind;

namespace NorthwindService
{
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=true)]
    public class Northwind: DataService<DB>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.UseVerboseErrors = true;
        }
    }
}

web.config のサービス部分は簡単です。

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  </system.serviceModel>

次に、テスト プロジェクトに対して、サービスへのサービス参照を追加します。astoria プロジェクトからテスト コードを取得しました。

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WcfClientTest.NorthwindService;

namespace WcfClientTest
{
    /// <summary>
    /// Summary description for WcfTest
    /// To run these tests, load this project, and somehow get a server running at the URI. 
    /// This can be done by updating the service reference to start the development server.
    /// </summary>
    [TestClass]
    public class WcfTest
    {
        private string baseURI = "http://127.0.0.1:49649/Northwind.svc";
        private DB ctx;

        /// <summary>
        /// Sets up test.
        /// </summary>
        [TestInitialize]
        public void SetUp()
        {
            ctx = new DB(new Uri(baseURI));
        }

        [TestCleanup]
        public void Cleanup()
        {
        }

        [TestMethod]
        public void Select_Simple_With_Variable()
        {
            int categoryID = 5;
            IQueryable<Product> result = from p in ctx.Products
                                         where p.CategoryID == categoryID
                                         select p;

            List<Product> products = result.ToList();
            Assert.AreEqual(7, products.Count());
        }

        [TestMethod]
        public void TestAddNew()
        {
            // add customer
            var c = new Customer
                        {
                            CustomerID = "XXXXX",
                            ContactTitle = "Prez",
                            Country = "USA",
                            ContactName = "Big Guy",
                            CompanyName = "Big Guy Company"
                        };
            ctx.AddToCustomers(c);
            ctx.SaveChanges();

            IQueryable<Customer> qCustomer = from cust in ctx.Customers
                                             where cust.CustomerID == "XXXXX"
                                             select cust;

            Customer c2 = qCustomer.FirstOrDefault();

            Assert.AreEqual("XXXXX", c2.CustomerID);

            if (c2 != null)
            {
                ctx.DeleteObject(c2);
            }
            ctx.SaveChanges();

            IQueryable<Customer> qCustomer2 = from cust in ctx.Customers
                                              where cust.ContactName == "Big Guy"
                                              select cust;
            // Returns null if the row isn't found.
            Customer c3 = qCustomer2.SingleOrDefault();
            Assert.AreEqual(null, c3);
        }
    }
}

私が持っているのはこれだけです。組み立てるのは難しくありません。今は問題を探しての解決策ですが、いつか使うつもりです。subsonic を完全にバイパスして、IQToolkit を直接使用することは可能であり、いくつかの T4 テンプレートとともに、非常に優れたシステムを備えています。

于 2009-05-27T12:59:09.527 に答える