score:6
Accepted answer
did you try set AllowTruncation=true
for your properities in City
class?
public class City
{
[BsonId]
[BsonRepresentation(BsonType.Int, AllowTruncation=true)]
public string id { get; set; }
[BsonRepresentation(BsonType.Int, AllowTruncation=true)]
public int value { get; set; }
}
How do I set the serialization options for the geo values using the official 10gen C# driver?
score:7
You typically don't want your model to know or care how it's being stored, so peppering it with MongoDB.Bson
attributes is not ideal. You can configure how MongoDB.Driver should read and store decimals with this config instead.
BsonSerializer.RegisterSerializer(
typeof(decimal),
new DecimalSerializer(BsonType.Double,
new RepresentationConverter(
true, // allow overflow, return decimal.MinValue or decimal.MaxValue instead
true //allow truncation
))
);
Source: stackoverflow.com
Related Articles
- mongodb data losing when run web service in c#
- OData WCF Data Services - Related data (by foreign key) doesn't show up when calling the service
- DataContext not visible when choosing data source for LinqDataSource
- Exception when changing data source to SQL
- c# Linq or code to extract groups from a single list of source data
- Purpose of EF 6.x DbContext Generator option when adding a new data item in Visual Studio
- Entity-framework code is slow when using Include() many times
- The data source does not support server-side data paging
- When should I dispose of a data context
- How can I use Nhibernate to retrieve data when the "WHERE IN()" have thousands of values? (too many parameters in the sql)
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- LINQ to SQL does not update when data has changed in database
- Forcing XDocument.ToString() to include the closing tag when there is no data
- Duplicate Rows when Data Binding with LINQ to Entities
- System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource
- LINQ to SQL - Compile error when extending data context with partial class and methods
- Why is my WCF Data Service not able to serve an automatically generated ADO.Net EDM?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Return Count from Netflix oData Service When the LINQ Count() Method Doesn't Work
- How does linq actually execute the code to retrieve data from the data source?
- Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
- LINQ Source Code Available
- What are the alternatives to using Expand in a LINQ to ADO.net Data Service Query?
- LINQ query performance issue when fetching data from db in MVC Razor
- .NET 4 Code Contracts: "requires unproven: source != null"
- Removing a single item from an enumerable source when the items are equal
- Is there a way to speed up this code that finds data changes in two XML files?
- Issues to consider when choosing data access technologies?
- There is already an open DataReader associated with this Command which must be closed first linq
- Selected combobox item in textbox, picturebox XML (XDocument)
- I want to convert this foreach loop to a LINQ statement
- How to convert this TSQL into Linq Method approach
- Simplify linq expression that orders children
- How do I return list of elements by attribute value
- LINQ cast int64 issue
- How do you set a type to an IEnumerable<> if the results will have many types?
- OrderBy / ThenBy looping - nested Lists in C#
- C# LINQ getting duplicates from a list
- I have loaded Excel files into .NET using LINQ, now how to bulk insert data into DB (oracle) tables?
- A type that implements IEnumerable 'System.Collections.Generic.List`1' cannot be initialized in a LINQ to Entities query
- Sorting list after Date then time
- GroupBy on multiple properties with complex type
- Building xml from scratch and getting result in string?
- async await with Select() in Linq
- Deserialize JSON to dictionary using LINQ to JSON
- How to perform subquery,group by and aggregate together using lambda or LINQ in C#
- Linq C# Joining null values on navigational properties
- Group list of objects based on timestamp