2010-10-04 61 views
0

我對VB很滿意,並有一個非常大的項目,我需要做的。我遇到過SubSonic,它看起來很棒。使用亞音速與vb.net

我不清楚我是否可以在VB中使用它。我見過一些帖子暗示他們做了,但在網站上它特別顯示了C#。

我可以在VB.NET中使用SubSonic嗎?

+0

題外話,但我們發現亞音速是相當有問題的,因此不再考慮在我們的項目中。只要你想找點東西並學習它,也許可以找一個類似的.Net工具(如CLSA,LLBLGen,NHydrate等)。 – 2010-10-04 20:04:00

+0

由於我使用SubSonic,我遇到了很多錯誤/問題。但通常我立即修復它們。 SubSonic的優點是易於理解/定製的架構,它具有輕量級的強大功能並且可以很好地擴展(除了xyzCollections,但您不必將它們用於較大的查詢)。但你說得對,還有其他很棒的產品,但我敢打賭,他們沒有一個在「從零到生產」的速度上擊敗亞音速;) – 2010-10-05 14:51:36

回答

4

SubSonic本身完全是用C#編寫的,但您的表和視圖的代碼生成也可用於vb.net。

對於SubSonic3您需要將VB-模板添加到您的項目

http://github.com/subsonic/SubSonic-3.0-Templates/tree/master//SubSonic.TemplatesVB/

對於SubSonic2必須添加一個/lang vb參數subcommander(sonic.exe) 不過,我個人堅持與C#代碼生成,因爲它是更大的測試,因爲更大的用戶羣,我想。

您可以將另一個c#類庫項目添加到您的解決方案(您應該爲您的DAL創建一個單獨的項目)並鏈接到您的vb.net網站項目中。我也運行這種設置。

有在這種情況下3個缺點:

1)您不能創建與Visual Studio Express版混合編程語言項目的解決方案。 2)如果你不想擴展生成的類(使用部分類,而不是繼承),你必須在c#中這樣做,因爲部分類必須在同一個項目中。 3)如果你改變你的c#項目的設計時間錯誤只會在下一次編譯後顯示(例如,如果你改變了你的vb項目中使用的列名並重新生成你的DAL,錯誤窗口只顯示這個錯誤,如果你編譯你的解決方案/ C#項目一次

在一天結束時,我會鼓勵你堅持使用C#,因爲它是更有趣的亞音速(linq,lamdas,...)編碼。但是,如果你不想,你應該罰款用VB。

一些例子,是simplier在C#中才達到

// in vb.net you have to add the _ modifier at the end of each line 
// one thing that gets annoying for large linq queries or 
// when using subsonics query tool 
var query = from p in products.All() 
      join c in prodctcategories.All() on p.categoryId equals c.id 
      where c.categoryName == "Food" 
      select new {p.productName, c.categoryName} 


// from the subsonic3 docs: 
//find a single product by ID 
var product = Product.SingleOrDefault(x => x.ProductID == 1); 

//get a list of products based on some criteria 
var products = Product.Find(x => x.ProductID <= 10); 


// You can write lamdas in vb.net but they don't look as nice as in c# 
Dim product = Product.SingleOrDefault(Function(x) x.ProductID = 1) 
Dim products = Product.Find(Function(x) x.ProductID <= 10) 

// If you have to write InlineQueries (subsonic's backdoor) you can do this 
// with c#. For vb.net you would need a) internal backing fields for the 
// poco class ProductResult and you would again need the concat 
// the query string with underscore, Environment.NewLine and & 
public class ProductResult 
{ 
    public int ProductId {get;set;} 
    public string ProductName {get;set;} 
} 

public List<ProductResult> GetProducts() 
{ 
    string query = @"SELECT p.productid, p.name as productname 
    FROM product p 
    INNER JOIN productcategories pc 
    WHERE pc.categoryname = 'Food' 
    ORDER BY p.productid ASC"; 

    var result = new CodingHorror(query).ExecuteTypedList<ProductResult>(); 
} 
+0

Thnaks for the response schlawiener – Dan 2010-10-05 11:40:20