Unhandled Exception: 'package:realm_dart/src/helpers.dart': error: line 26 pos 3: native function 'Helpers_invokeStatic' (2 arguments) cannot be found - mongodb

Unhandled Exception: 'package:realm_dart/src/helpers.dart': error: line 26 pos 3: native function 'Helpers_invokeStatic' (2 arguments) cannot be found
While starting the application its working perfectly and fetching data but when I restart the application it throws above error.
main.dart
void ints() {
print("initState");
var config = new Configuration();
config.schema.add(Car);
var realm = new Realm(config);
realm.write(() {
print("realm write callback");
var car = realm.create(new Car()..make = "Audi");
print("The car is ${car.make}");
car.make = "VW";
print("The car is ${car.make}");
});
var objects = realm.objects<Car>();
var indexedCar = objects[1];
print('here');
print("The indexedCar is ${indexedCar.make}");
}
Configuration.dart
add(Type type) {
print(type);
var schema = Helpers.invokeStatic(type, "getSchema");
//set the static field on the T class.
TypeStaticProperties.setValue(type, "schema", schema);
// _generateSchema(type);
innerList.add(type);
}
Helpers.dart
class Helpers {
static DateTime createDateTime(int miliseconds) {
return DateTime.fromMillisecondsSinceEpoch(miliseconds, isUtc: true);
}
static dynamic invokeStatic(Type type, String name) native "Helpers_invokeStatic";
}

Related

Azure Search CreateIndexAsync fails with CamelCase field names FieldBuilder

Azure Search V11
I can't get this to work. But with the standard FieldBuilder the index is created.
private static async Task CreateIndexAsync(SearchIndexClient indexClient, string indexName, Type type)
{
var builder = new FieldBuilder
{
Serializer = new JsonObjectSerializer(new JsonSerializerOptions {PropertyNamingPolicy = new CamelCaseNamingPolicy()})
};
var searchFields = builder.Build(type).ToArray();
var definition = new SearchIndex(indexName, searchFields);
await indexClient.CreateIndexAsync(definition);
}
`
public class CamelCaseNamingPolicy : JsonNamingPolicy
{
public override string ConvertName(string name)
{
return char.ToLower(name[0]) + name.Substring(1);
}
}
See our sample for FieldBuilder. Basically, you must use a naming policy for both FieldBuilder and the SearchClient:
var clientOptions = new SearchClientOptions
{
Serializer = new JsonObjectSerializer(
new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
}),
};
var builder = new FieldBuilder
{
Serializer = clientOptions.Serializer,
};
var index = new SearchIndex("name")
{
Fields = builder.Build(type),
};
var indexClient = new SearchIndexClient(uri, clientOptions);
await indexClient.CreateIndexAsync(index);
await Task.DelayAsync(5000); // can take a little while
var searchClient = new SearchClient(uri, clientOptions);
var response = await searchClient.SearchAsync("whatever");
While this sample works (our sample code comes from oft-executed tests), if you have further troubles, please be sure to post the exact exception message you are getting.

Using Dynamic LINQ with EF.Functions.Like

On the Dynamic LINQ website there's an example using the Like function.
I am unable to get it to work with ef core 3.1
[Test]
public void DynamicQuery()
{
using var context = new SamDBContext(Builder.Options);
var config = new ParsingConfig { ResolveTypesBySimpleName = true };
var lst = context.Contacts.Where(config, "DynamicFunctions.Like(FirstName, \"%Ann%\")".ToList();
lst.Should().HaveCountGreaterThan(1);
}
Example from the Dynamic LINQ website
var example1 = Cars.Where(c => EF.Functions.Like(c.Brand, "%t%"));
example1.Dump();
var config = new ParsingConfig { ResolveTypesBySimpleName = true };
var example2 = Cars.Where(config, "DynamicFunctions.Like(Brand, \"%t%\")");
example2.Dump();
Looks like my code. But I am getting the following error
System.Linq.Dynamic.Core.Exceptions.ParseException : No property or field 'DynamicFunctions' exists in type 'Contact'
you don't need the ResolveTypesBySimpleName, implement your wont type provider.
The piece below people to use PostgreSQL ILike with unnaccent
public class LinqCustomProvider : DefaultDynamicLinqCustomTypeProvider
{
public override HashSet<Type> GetCustomTypes()
{
var result = base.GetCustomTypes();
result.Add(typeof(NpgsqlFullTextSearchDbFunctionsExtensions));
result.Add(typeof(NpgsqlDbFunctionsExtensions));
result.Add(typeof(DbFunctionsExtensions));
result.Add(typeof(DbFunctions));
result.Add(typeof(EF));
return result;
}
}
// ....
var expressionString = $"EF.Functions.ILike(EF.Functions.Unaccent(People.Name), \"%{value}%\")";
var config = new ParsingConfig()
{
DateTimeIsParsedAsUTC = true,
CustomTypeProvider = new LinqCustomProvider()
};
return query.Where(config, expressionString);
Hope this helps people, took me some time to get this sorted.

System.Linq.Queryable.Except is not supported in Entity Framework Core

Please note this error message :
System.NotSupportedException: 'Could not parse expression
'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable
This overload of the method 'System.Linq.Queryable.Except' is
currently not supported.'
Is supported in newer versions of ef core?
my code :
var tuple = SearchBrand(searchTerm);
var result = GetExceptionsBrand(tuple.Item1, categoryId);
return Json(new
{
iTotalDisplayRecords = tuple.Item2,
iDisplayedBrand = result
.Skip(page * 10)
.Take(10)
.ToList(),
});
public async Task<Tuple<IQueryable<BrandDto>, int, int>>SearchBrand(string searchTerm)
{
var result = _context.Brands
.Where(c => c.IsDeleted == displayIsDeleted)
.WhereDynamic(searchTerm)
return new Tuple<IQueryable<BrandDto>, int, int>(result,
filteredResultsCount, totalResultsCount);
}
public IQueryable<BrandDto> GetExceptionsBrand(IEnumerable<BrandDto> filteredBrand, int categoryId)
{
var query = _context.CategoriesBrands.Where(x => x.CategoryId == categoryId);
var selectedList = new List<BrandDto>();
foreach (var item in query)
{
var cb = new BrandDto()
{
BrandDto_BrandId = item.BrandId
};
selectedList.Add(cb);
}
IQueryable<BrandDto> ExcpetList = filteredBrand.AsQueryable().Except(selectedList, new ComparerBrand());
return ExcpetList;
}

not able to save documents in mongodb c# with .Net driver 2.0

I want to save the document in a collection my method is as below but it is not saving at all.
internal static void InitializeDb()
{
var db = GetConnection();
var collection = db.GetCollection<BsonDocument>("locations");
var locations = new List<BsonDocument>();
var json = JObject.Parse(File.ReadAllText(#"..\..\test_files\TestData.json"));
foreach (var d in json["locations"])
{
using (var jsonReader = new JsonReader(d.ToString()))
{
var context = BsonDeserializationContext.CreateRoot(jsonReader);
var document = collection.DocumentSerializer.Deserialize(context);
locations.Add(document);
}
}
collection.InsertManyAsync(locations);
}
If I made async and await then it runs lately, I need to run this first and then only test the data.
For future reference, wait() at end of async method work like synchronously
internal static void InitializeDb()
{
var db = GetConnection();
var collection = db.GetCollection<BsonDocument>("locations");
var locations = new List<BsonDocument>();
var json = JObject.Parse(File.ReadAllText(#"..\..\test_files\TestData.json"));
foreach (var d in json["locations"])
{
using (var jsonReader = new JsonReader(d.ToString()))
{
var context = BsonDeserializationContext.CreateRoot(jsonReader);
var document = collection.DocumentSerializer.Deserialize(context);
locations.Add(document);
}
}
collection.InsertManyAsync(locations).wait();
}

Access to "global" var in ActionScript 3.0 - AIR application

In a AIR Mobile application I have this code:
import character.*;
var player_1 = new characterObject("Player 1");
var player_2 = new characterObject("Player 2");
In the package class:
package character {
public class characterObject extends MovieClip {
public var characterName: Number;
public var playerCounter: Number = 0;
public function characterObject(myName: String) {
characterName = myName;
playerCounter++;
}
}
Can I access to player_1.playerCounter property inside player_2 object istance?
I need to increes the value of players only if total_player (a var that I want create as sum of player_1.playerCounter + player_2.playerCounter + player_n.playerCounter ...) is < of x.
Bad idea.
Yo can try next thing
package character {
public class CharactersModel extends Object{
private var _chars : Array = [];
public function addCharacter(char : characterObject) {
_chars.push(char);
}
public function getChars() : Array {
return _chars;
}
public function getCharByName(name : String ) : characterObject {
//select from array and return
//use it instead of null
return null;
}
}
}
and update characterObject like this
private var _model : CharactersModel;
public function characterObject(model : CharactersModel ,myName: String) {
_model = model;
characterName = myName;
playerCounter++;
model.addCharacter(this);
}
public function getOtherChar(name : String) {
return _model.getCharByName(name);
}
and finally
import character.*;
var model : CharactersModel = new CharactersModel();
var player_1 = new characterObject(model ,"Player 1");
var player_2 = new characterObject(model ,"Player 2");
I would create a vector to hold character instances outside of the characterObject class. Then you could refer to the length of the vector for the current amount.
var characters:Vector.<characterObject> = new Vector.<characterObject>();
characters.push( new characterObject("Player 1") );
characters.push( new characterObject("Player 2") );
trace( characters.length ); // 2