【发布时间】:2021-08-09 14:53:50
【问题描述】:
我有一个实体类
public class City
{
[BsonId]
public string id { get; set; }
public int value { get; set; }
}
我创建了一个 web 服务,并且有一个 webmethod
[WebMethod]
public List<City> linQuery()
{
MongoConn dao = new MongoConn();
MongoServer mongo = dao.getConnection();
List<City> list = new List<City>();
string dbName = dao.dbName();
var db = mongo.GetDatabase(dbName);
Console.WriteLine(db);
using (mongo.RequestStart(db))
{
var collection = db.GetCollection<City>("cityMap");
IQueryable<City> cities = collection.AsQueryable().Where(c => c.value > 1200);
foreach (City city in cities)
list.Add(city);
return list;
}
}
当我运行服务时,我得到了那个错误:
System.IO.FileFormatException: An error occurred while deserializing the value property of class WebService1.City: Truncation resulted in data loss. ---> MongoDB.Bson.TruncationException: Truncation resulted in data loss.
我该如何解决这个问题? 感谢您的帮助。
【问题讨论】:
-
更改字段 public int value { get;放; } to public double value { get;放; }
-
@ToanNguyen 感谢您的回答。我更改了属性类型和服务不抛出异常。
标签: c# linq web-services mongodb