Details
-
Bug
-
Resolution: Won't Fix
-
Blocker - P1
-
None
-
1.10
-
None
-
None
Description
Here is the code
|
C# |
|
|
public class MainMongo
|
{
|
public MongoDB.Bson.ObjectId Id { get; set; }
|
}
|
|
|
public class DbRef<T> : MongoDB.Driver.MongoDBRef
|
{
|
public DbRef(string ColName, MongoDB.Bson.BsonValue Id) : base(ColName, Id)
|
{
|
|
|
}
|
|
|
[MongoDB.Bson.Serialization.Attributes.BsonIgnore()]
|
public T Value
|
{
|
get
|
{
|
return new MongoDB.Driver.MongoClient("mongodb://localhost").GetServer().GetDatabase("Wik").FetchDBRefAs<T>(this);
|
}
|
}
|
|
|
}
|
|
|
|
public class Car : MainMongo
|
{
|
public DateTime BuildDate { get; set; }
|
|
|
}
|
|
|
public class Player : MainMongo
|
{
|
|
|
public string Name { get; set; }
|
public List<DbRef<Car>> Cars { get; set; }
|
|
|
}
|
|
|
|
|
//Here is code that uses database
|
|
|
var CarCol = mdb.GetCollection<Car>("Car");
|
var PlayerCol = mdb.GetCollection<Player>("Player");
|
CarCol.Drop();
|
PlayerCol.Drop();
|
|
|
|
|
var Ca = new Car() { BuildDate = DateTime.Now };
|
CarCol.Save<Car>(Ca);
|
|
|
var Pl = new Player() { Name = "Mohsen", Cars = new List<DbRef<Car>>(new DbRef<Car>[] { new DbRef<Car>("Car", Ca.Id) }) };
|
PlayerCol.Save<Player>(Pl);
|
|
|
var GetCarDbRef = PlayerCol.AsQueryable().OfType<Player>().FirstOrDefault().Cars.FirstOrDefault();
|
bool IsNull1 = GetCarDbRef.CollectionName == null; //true
|
bool IsNull2 = GetCarDbRef.DatabaseName == null; //true
|
bool IsNull3 = GetCarDbRef.Id == null; //true
|
|
|
|
|
|
All values of DbRef which has inherited from MongoDbRef are null!