Z.EntityFramework.Plus.QueryCache.EF6 Requires QueryDeferred Library? - entity-framework

When trying to use the QueryCache library to do some L2 caching of a few entities, I am receiving a compiler error on .FromCache() indicating the QueryDeferred library is required. Documentation indicates QueryCache can be used as stand-alone.
using Z.EntityFramework.Plus;
namespace LookupValuesMap.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
LookupValueContext ctx = new LookupValueContext();
var companies = ctx.Companies.FromCache().ToList(); <-- error
Here is the error:
Error CS0012 The type 'QueryDeferred<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Z.EntityFramework.Plus.QueryDeferred.EF6, Version=1.6.8.0, Culture=neutral, PublicKeyToken=59b66d028979105b'.
Thank you in advance!
J Kent

Disclaimer: I'm the owner of the project Entity Framework Plus
Due to how the library has been built, some "standalone" features like this one may have the Z.EntityFramework.Plus.QueryDeferred.EF6 requirement.
You can download the version from: NuGet
We will eventually fix it for no longer having to have this dependence.

Related

Unity google-play-core review issue

I added the google play core package as instructed in the repo, and added the code according to the documentation here
I receive the following error: CS0246: The type or namespace name 'PlayAsyncOperation<,>' could not be found (are you missing a using directive or an assembly reference?)
This error shows at _reviewManager.RequestReviewFlow(); and _reviewManager.LaunchReviewFlow(_playReviewInfo)
Any idea what could be the issue?
My full code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Google.Play.Review;
public class ReviewCodes : MonoBehaviour
{
private ReviewManager _reviewManager;
private PlayReviewInfo _playReviewInfo;
// Start is called before the first frame update
void Start()
{
StartCoroutine(RequestReviews());
}
// Update is called once per frame
void Update()
{
}
IEnumerator RequestReviews()
{
// Create instance of ReviewManager
_reviewManager = new ReviewManager();
var requestFlowOperation = _reviewManager.RequestReviewFlow();
yield return requestFlowOperation;
if (requestFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
_playReviewInfo = requestFlowOperation.GetResult();
var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);
yield return launchFlowOperation;
_playReviewInfo = null; // Reset the object
if (launchFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
}
}
"are you missing a using directive or an assembly reference?"
These are following situation which causes a compiler error:
Check if the name of the type or namespace is correct, as most of the time you can get this error when the compiler cannot find that namespace.
Check if you have added the reference to the assembly that contains the namespace. Ex: Your code can be in "using XYZ;"
but if your project does not reference assembly then you can get a CS0246 error.
Try: using Google.Play.Common;
the order might be your problem. You also not only have to import the Google Core Package. You also have to import the Google Review Plugin. The core plugin overrides assemblies and files which then can't be used by the review assembly.
Step-by-Step solution:
Import google-play-plugins-1.7.0.unitypackage
Import com.google.play.review-1.7.0.unitypackage
Make sure to restart your IDE or reload the code in your IDE after this steps.
In older versions in unity there was an option to download this packages with the help of the unity package manager. Now you have to use the official github repository from Google. See Downloading the plugins or just use the official provided .unitypackages from Google

How to get DPI device to PCL in Xamarin. Forms? - Followup

Using Xamarin Forms Visual Studio 2019.
I need to get the DPI of the device.
This post has a solution:
How to get DPI device to PCL in Xamarin. Forms?
Implementing the solution gave problems:
When applying the answer above I get this error message:
The type or namespace name 'DependencyAttribute' could not be found
(are you missing a using directive or an assembly reference?)
In your android implementation, add a new class:
[assembly: Dependency(typeof(DisplayInfo))]
namespace .....
--I solved this compiler problem by replacing with:
using Xamarin.Essentials;
[assembly: Xamarin.Forms.Dependency(typeof(DisplayInfo))]
However when I compile and run the code, it falls over when I try consume this in the Xamarin Core Code:
int dpi = DependencyService.Get<IDisplayInfo>().GetDisplayDpi();
I get this runtime error on the above line:
System.NullReferenceException: Object reference not set to an instance
of an object
Any ideas? I would have added this question as a comment on the original, but as a new user do not have the points to do this... If someone could drop a comment on the original question's solution pointing it to this URL that would be helpful too.
So the answer to my own question:
The solution original offered said do this:
In your android implementation, add a new class:
[assembly: Dependency(typeof(DisplayInfo))]
namespace YourAppNamespace.Droid
{
public class DisplayInfo : IDisplayInfo
{
public int GetDisplayWidth()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.WidthPixels;
}
public int GetDisplayHeight()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.HeightPixels;
}
public int GetDisplayDpi()
{
(int)Android.App.Application.Context.Resources.DisplayMetrics.DensityDpi;
}
}
}
The problem I did not see anywhere in the Android code that initialised this class, and I was unsure how best to do this really.
So I followed guidance for implementing the interface directly in the Android MainActivity.cs file, and this worked.. The video I watched to help me on that is here:
https://www.youtube.com/watch?v=lgcnYDb6cRQ&t=19s

Exception Thrown by Manatee.Trello.RestSharp.RestSharpResponse

I just came across an exception while trying something with Manatee.Trello. I was trying to create a Func like this:
var criteria = new List<string>
{
"(put a board ID here)"
};
var query = new Func<IEnumerable<Manatee.Trello.Member>, IEnumerable<Manatee.Trello.Board>>(
members =>
{
foreach (var member in members)
{
var selectedBoards = member.Boards.Where(b => criteria.Contains(b.Id, StringComparer.Ordinal));
boards.AddRange(selectedBoards); // Exception thrown here
}
return boards;
});
But the line marked above throws this exception:
System.TypeLoadException
{"Method 'get_StatusCode' in type 'Manatee.Trello.RestSharp.RestSharpResponse' from assembly 'Manatee.Trello.RestSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=783b036be1eaf5a7' does not have an implementation.":"Manatee.Trello.RestSharp.RestSharpResponse"}
I'm not sure if this is something I'm doing wrong with my code, or some kind of setup error I made in setting up my project with Manatee.Trello, perhaps the NuGet packages are jacked up...
Any tips on where to start looking would be much appreciated.
This situation was remedied by changing from the RestSharp provider included in Manatee.Trello to the provider in Manatee.Trello.WebApi. As I discovered in the library's documentation:
Manatee.Trello.RestSharp is backed by (you guessed it) RestSharp.
There have been some issues with the .Net 4.5+ versions, so it's
suggested you don't use this one unless you are using .Net 4.0 or
earlier.
Indeed, I am using .Net 4.5.2.

Data driven unit test breaking entity framework connection

I have an application that uses entity framework. I am writing a unit test in which I would like to use data driven testing from a CSV file.
However, when I run the test, I get an error that the sqlserver provider cannot be loaded:
Initialization method UnitTest.CalculationTest.MyTestInitialize threw
exception. System.InvalidOperationException:
System.InvalidOperationException: The Entity Framework provider type
'System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer' registered in the application config file
for the ADO.NET provider with invariant name 'System.Data.SqlClient'
could not be loaded. Make sure that the assembly-qualified name is
used and that the assembly is available to the running application.
If I remove the data driven aspects and just test a single value, then the test works.
If I just use the data driven aspects and remove the Entity Framework stuff, then the test works.
So, its only when I try to use data driven test with entity framework active at the same time do I get the error. So, where am I going wrong here?
Here's my test method:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}
So I managed to work it out in the end. For future reference, here's the solution:
Rob Lang's post, Entity Framework upgrade to 6 configuration and nuget magic, reminded me of the issue here:
When a type cannot be loaded for a DLL that is referenced in a
project, it usually means that it has not been copied to the output
bin/ directory. When you're not using a type from a referenced
library, it will not be copied.
And this will raise its ugly head the moment you use deployment items in your tests. If you use a deployment item in your test, then all of the required binaries are copied to the deployment directory. Problem is, if you are using dynamically loaded items, then the test suite does not know it has to copy those items.
With Entity Framework, this means that your providers will not be copied to the deployment location and you will receive the error as per my question.
To resolve the issue, simply ensure that your entity framework provider is also marked as a deployment item.
So, note the inclusion of DeploymentItem(#"EntityFramework.SqlServer.dll") in my test attributes. All works perfectly from here:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")
, DeploymentItem(#"EntityFramework.SqlServer.dll")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}

Multiple class files in a Zephir extension

I'm doing some experiments with Phalcon Zephir to see how well it can convert some of my libraries to PHP extensions.
I have two PHP classes, each already defined in its own file: the Zephir notes are quite clear that this must be the case.
trienode.zep
namespace tries;
class trienode
{
public children;
public valueNode = false;
public value = null;
public function __construct()
{
let this->children = [];
}
}
and
trie.zep
namespace tries;
class trie {
private trie;
public function __construct() {
let this->trie = new trienode();
}
}
But whenever I try to compile the classes using zephir compile, I get
Warning: Class "trienode" does not exist at compile time in /home/vagrant/ext/tries/tries/trie.zep on 8 [nonexistent-class]
let this->trie = new trienode();
---------------------------------------^
(and if I continue through the build process, and install the resultant .so file, it errors when I try to use it from within a PHP script)
<?php
namespace tries;
$test = new trie;
giving
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/tries.so' - /usr/lib/php5/20121212/tries.so: undefined symbol: zephir_tries_trie_init in Unknown on line 0
PHP Fatal error: Class 'tries\trie' not found in /home/vagrant/triesTest.php on line 5
I've looked through the Zephir documentation, and various blog posts, but can't find any examples of building an extension that comprises more than a single class file.
Has anybody succeeded in building an extension using Zephir that does comprise more than a single class? And if so, what settings or configuration options (or additional steps) does it require to build a working so?
It looks like the namespace has to be included in the call.
let this->trie = new tries\trienode();
// ^^^^^^
I didn't see this explicitly mentioned in the documentation, but is hinted at (pardon the pun) in the Return Type Hints section, which uses the namespace in the hints.
Changing your example class to that shown above allows the extension to compile as desired.