Subsonic 亚音速3阿尔法和x2B;ado.net数据服务任何示例

Subsonic 亚音速3阿尔法和x2B;ado.net数据服务任何示例,subsonic,wcf-data-services,Subsonic,Wcf Data Services,互联网上有一些资源介绍了Astoria的亚音速预览2: 及工作样本 我对亚音速tt应用了所有相应的更改,但未能使MSDN项目正常工作。 在消除: a) 阿斯托里亚不喜欢 QuerySurface.tt中的私有DB(){},所以我盲目地将构造函数公开 b) 不确定如何生成复合主键 <# if(EnableForUseWIthAstoria) { #> [System.Data.Services.Common.DataServiceKey("<#=pk#>")] <

互联网上有一些资源介绍了Astoria的亚音速预览2:

及工作样本

我对亚音速tt应用了所有相应的更改,但未能使MSDN项目正常工作。 在消除:

a) 阿斯托里亚不喜欢 QuerySurface.tt中的私有DB(){},所以我盲目地将构造函数公开

b) 不确定如何生成复合主键

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

[System.Data.Services.Common.DataServiceKey("OrderID", "ProductID")] 
所以就排除了这个表

当前的障碍

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

        Customers c = q.First();
结果例外: 找不到细分市场“客户”的资源


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

是的,我签入了带有IUpdatable接口的ss3版本,并从可更新数据库类继承了DB query surface类。我还为它包括了一个启动测试项目。很好的一点是,您可以使用Uri构造一个DB类,然后开始使用服务。但它不是当前核心的一部分,它需要一个新类和一些重新排列,再加上一些小的模板更改。我认为这是其中一个领域,人们将不断地重新发明这个东西,而不是建立在以前的工作上。我想在这个项目中做一些更改,但没有成功,比如在运行时设置多个数据库、ado.net服务等。我想我必须永久地将自己的版本分支

具有显示UpdateableDatabase类的附件

我将其添加到
亚音速类。t包括

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

...

[System.Data.Services.Common.DataServiceKey("<#=PrimaryKey #>")]
public string[] GetTablePrimaryKeys(string tableSchema, string tableName)

并建立正确的字符串。

我不知道是否可以压缩解决方案并给出它,因为涉及亚音速许可证。它不是亚音速的,大约有2个月了(过时了)。我只是运行了这个项目来测试它是否还在工作,而且它确实在工作。以下是执行此操作的步骤:

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

公共部分类DB:UpdateableDatabase

UpdateableDatabase.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;
        }
    }
}
使用System.Data.Services;
使用北风;
名称空间NorthwindService
{
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=true)]
公共类北风:数据服务
{
//此方法只调用一次以初始化服务范围策略。
公共静态无效初始化服务(IDataServiceConfiguration配置)
{
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);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用Microsoft.VisualStudio.TestTools.UnitTesting;
使用wcfclientset.NorthwindService;
命名空间WCFClientSet
{
/// 
///WcfTest的摘要说明
///要运行这些测试,请加载此项目,并以某种方式使服务器在URI处运行。
///这可以通过更新服务引用来启动开发服务器来实现。
/// 
[测试类]
公共类WcfTest
{
专用字符串baseURI=”http://127.0.0.1:49649/Northwind.svc";
私人数据库ctx;
/// 
///设置测试。
/// 
[测试初始化]
公共作废设置()
{
ctx=新的DB(新的Uri(baseURI));
}
[测试清理]
公共空间清理()
{
}
[测试方法]
public void使用变量()选择\u Simple\u
{
int categoryID=5;
IQueryable结果=来自ctx.Products中的p
其中p.CategoryID==CategoryID
选择p;
列表产品=result.ToList();
aresequal(7,products.Count());
}
[测试方法]
公共无效测试新()
{
//添加客户
var c=新客户
{
CustomerID=“XXXXX”,
ContactTitle=“Prez”,
Country=“美国”,
ContactName=“大个子”,
CompanyName=“大家伙公司”
};
ctx.添加到客户(c);
ctx.SaveChanges();
IQueryable QCCustomer=来自ctx中的客户。客户
其中cust.CustomerID==“XXXXX”
选择客户;
Customer c2=qCustomer.FirstOrDefault();
Assert.AreEqual(“XXXXX”,c2.CustomerID);
如果(c2!=null)
{
ctx.DeleteObject(c2);
}
ctx.SaveChanges();
IQueryable QCCustomer2=来自ctx.Customers中的客户
其中cust.ContactName==“大个子”
选择客户;
//如果找不到行,则返回null。
客户c3=qCustomer2.SingleOrDefault();
aresequal(null,c3);
}
}
}

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

以下是iUpdateable界面的补丁和所需的模板更改。我99%肯定这不会进入最终项目,但至少你可以看到我是如何做到的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); } } }