日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

db4o发布7.2,出现.NET 3.5版本,支持LINQ

發布時間:2023/12/14 asp.net 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 db4o发布7.2,出现.NET 3.5版本,支持LINQ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

db4o發布7.2,出現.NET 3.5版本,支持LINQ

Db4Object剛剛發布了db4o的7.2beta,除了以前支持如下的平臺:.NET 1.1,.NET 2.0,Mono外,現在還支持.NET 3.5了。當然支持.NET 3.5,最主要的時候要來支持LINQ。

關于LINQ,我稍后再講。現在講講7.2中最大的新特性——Transparent Activation(透明激活)。關于7.0版本的其他新特性,可以參看我在InfoQ上的文章《Db4Objects發布Db4o 7.0,支持透明激活》。

要講到透明激活,我們先來看看之前激活存在的問題。所謂激活,就是在對象從磁盤文件載入到內存過程中,如何加載層級對象的過程。由于對象的層級關系可以無限關聯的,所以,db4o之前使用“深度”的概念來明確表明處理對象的時候需要,處理到多少層。但是,這種方式對編程帶來很多麻煩,我們在寫代碼的時候需要隨時關心,我們大概要加載多深的對象。這樣的估計有時候會比要使用到的多,有時候又會少。多了,造成資源的浪費,少了,不能正確的處理需要處理到的對象。

下面我引用,db4o文檔中對這個問題的描述(英文的我就不翻譯了):

We can reuse most of the code from the?Deep Graphs chapter?and get it to work with Transparent Activation.
As a first step we should fill up our database with Car, Pilot and SensorReadout objects, so we have some objects to work with.

// storeCarAndSnapshots
Pilot pilot = new Pilot("Kimi Raikkonen", 110);
Car car = new Car("Ferrari");
car.Pilot = pilot;
for (int i = 0; i < 5; i++)
{
??? car.snapshot();
}
db.Store(car);

If we now rerun the code to traverse all cars and their sensor readings, we are again confronted with the same problem that we had before, we end up with some leaves of our object graph being null.??

// retrieveSnapshotsSequentially
IObjectSet result = db.QueryByExample(typeof (Car));
Car car = (Car) result.Next();
SensorReadout readout = car.History;
while (readout != null)
{
??? Console.WriteLine(readout);
??? readout = readout.Next;
}

為了解決這個問題,db4o在7.0中提出了透明激活的概念,即db4o透明地幫我們處理對象激活的問題。這樣可以提供性能,讓我們編程更方便。

再次引用db4o文檔的代碼:

Let's configure db4o to run in Transparent Activation mode and let's try again:

// configureTransparentActivation
Db4oFactory.Configure().Add(new TransparentActivationSupport());

// retrieveSnapshotsSequentially
IObjectSet result = db.QueryByExample(typeof (Car));
Car car = (Car) result.Next();
SensorReadout readout = car.History;
while (readout != null)
{
??? Console.WriteLine(readout);
??? readout = readout.Next;
}

Wow it worked! Is it really that easy? Principally yes. When db4o is run in Transparent Activation mode there are no surprises with null members that have not yet been read from the database.

好了,透明激活就講到這里,現在來看看LINQ的支持。Linq在7.0發布之前,在db4o上已經有一個linq to db4o的項目在做前期研究了,現在只是把linq to db4o合并到7.2中一起發布。

linq to db4o提供了一個額外的程序集:Db4objects.Db4o.Linq

要使用linq to db4o,只需要在項目中引用這個程序集。然后打開一個db4o數據庫,就可以使用linq語法查詢數據了:

Let's prepare some objects in our database to query against:

// storeObjects
db.Store(new Car("Ferrari", (new Pilot("Michael Schumacher", 100))));
db.Store(new Car("BMW", (new Pilot("Rubens Barrichello", 99))));

The simplest LINQ query will look like this:

// retrievePilot
IEnumerable<Pilot> result = from Pilot p in db
??????????????????????????? where p.Name.StartsWith("Michael")
??????????????????????????? select p;
ListResult(result);

You can see that we are using db4o object container as a datasource, the rest of the syntax is generic to all LINQ queries.
Now let's try a bit more complex selection:

// retrievePilotByCar
IEnumerable<Pilot> result = from Car c in db
??????????????????????????? where c.Model.StartsWith("F")
??????????????????????????? && (c.Pilot.Points > 99 && c.Pilot.Points <150)
??????????????????????????? select c.Pilot;
ListResult(result);

另外這里,也有一個linq to db4o的例子:Linq is here!

通過linq來查詢db4o確實帶來了很多方便,不過現在linq to db4o還沒有非常成熟,期待其更加完善成熟。

大家對db4o 7.2有興趣的,可以到這里下載來試試。

轉載:http://www.cnblogs.com/redmoon/archive/2008/02/23/1078619.html

轉載于:https://www.cnblogs.com/tianciliangen/p/6827985.html

總結

以上是生活随笔為你收集整理的db4o发布7.2,出现.NET 3.5版本,支持LINQ的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。