0

互联网上有几个资源描述了 Astoria 的 subsonic 预览 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

我对亚音速 tt(s) 应用了所有相应的更改,但是没有设法使 MSDN 项目工作。消除后:

a) Astoria 不喜欢 QuerySurface.tt 中的 private DB() { } ,所以我盲目地将构造函数公开

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

导致异常:未找到段“客户”的资源

有没有人尝试过或知道另一个最新和最伟大的样本存在?

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 类,并开始针对服务工作。但它不是当前核心的一部分,它需要一个新的类和一些重新排列,加上小的模板更改。我认为这是人们将不断重新发明这件事而不是建立在以前的工作之上的领域之一。我想对项目进行一些更改,但他们没有做到,例如在运行时设置多个数据库、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 作弊,并通过直接编辑文件添加了第二个密钥。您可以轻松地在以下位置编写这样的方法DatabaseSchema.ttinclude

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

并建立正确的字符串。

于 2009-05-27T07:01:34.150 回答
0

我不知道我是否可以压缩解决方案并将其发布,因为涉及亚音速许可证。它不是亚音速的,大约 2 个月大(过时)。我刚刚运行该项目以测试它是否仍在工作,并且确实如此。以下是执行此操作的步骤:

使用上面提到的 UpdatableDatabase 类。然后从中派生数据库(将其放入模板中):

公共部分类数据库: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);
        }
    }
}

这就是我所拥有的,它并不难放在一起。现在它是寻找问题的解决方案,但我打算在某个时候使用它。可以完全绕过亚音速,直接使用 IQToolkit,以及一些 T4 模板有一个非常好的系统。

于 2009-05-27T12:59:09.527 回答
0

这是 IUpdatable 接口的补丁和所需的模板更改。我 99% 确定这不会进入最终项目,但至少你可以看到我是如何做到的。

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

于 2009-05-27T19:11:06.390 回答