Can I have a .NET Class Library project with Entity Framework 6.1.1 (in windowsazure.mobileservices.backend.entity nuget package) work with Xamarin.Forms PCL app? Is this achievable? If not what are the possible complications?
Question Background:
I am working on a Xamarin.Forms cross platform PCL app with Azure Mobile Services back-end, targeting Android, iOS, Windows 8.1 and WinPhone 8.1. I actually dont care about Windows 8.1 but Visual Studio does not allow me to remove this target. So it stays.
Azure Mobile Services is setup, but I need the tables to be generated automatically (strongly avoiding manually typing table definitions in azure portal). I decided to go EF code first way with windowsazure.mobileservices.backend.entity nuget package to achieve this. However, the Xamarin.Forms PCL project does not support additional assemblies.
I am thinking of adding this package into a separate class library project and referring to it from the PCL project.
Thanks for your help!
The EntityData type is the required superclass of DTOs on the server SDK. Unfortunately, it has dependencies that are not supported in a PCL project, so it has to be used with a full .NET 4.5 project.
You could instead use partial classes to share DTOs between client and server. Just put all of the non system property types in a common code file that's shared between client and server. Then, on the client, add the system property implementation (ID field, UpdatedAt optionally, Version optionally). On the server, add another partial class definition that inherits from EntityData.
Related
I got lost very quickly in all the moves from .Net Framework to .Net Standard to .Net Core. Could someone please just tell me what I need to do to get my projects to work together?
Here's the situation: I've got a simple web service written in ASP.Net that contains a set of classes built by Entity Framework from an existing database using a "scaffold" command. The web service can respond to a request for a list of coils from a database. The list is delivered as a JSON-serialized string.
I have a simple mobile app developed in Xamarin. I want it to accept the JSON string and deserialize it into a list of Coil objects. To do that, I need to add a reference to the web service project. But when I try to do that, I get complaints that the targets of the two projects are not compatible.
The choices for target frameworks for the web service are .Net 5.0 and .Net Core 1.0 through 3.1. The choices for target frameworks for the Xamarin app are .Net Standard 1.0 through 2.1. I have been unable to find a combination of these choices that works. What choices should I use that would enable me to add a reference to the web service project to the Xamarin project?
Or should I split the Entity Framework-generated classes out into a separate library? That would probably be a better project structure anyway. In that case, I'd have three projects. The target framework chosen for the library would have to be compatible with frameworks chosen for the web service and the Xamarin app, but the framework for the web service would no longer have to be compatible with the Xamarin app's framework.
Or perhaps I should rebuild all of these from scratch. These are all trivial projects, done mainly for education, although the Xamarin app might be useful in the real world. Recreating them would be easy. Again, if I did this, what targets should I use?
All development has been done in Visual Studio 2019.
I am converting xamarin forms pcl to .net standard. In the project I use skia sharp and azure mobileservices.
My understanding was that if I reference these libraries in the .net standard class library and then add a reference to this .net standard class library in my android/ios/uwp projects all would be fine.
However it seems that I need to add the nuget packages for skiasharp and azure mobileservices to each project (android/ios/uwp). Is this indeed the case? if so, how is this better than using PCL?
I got the android project working, but I needed to add all the nuget packages to the android project.
I got the uwp project working without any nuget packages, which confuses me even further.
Using PCL and .NET Standard are basically the same - both are just API contracts or a subset of the full .NET Framework. But there is a MAJOR advantage to .NET Standard: .NET Standard has far more APIs - especially if you are using 1.3+ (netstandard1.3 has the System.IO APIs which aren't available in PCL).
With regards to NuGets, you typically still need to reference the NuGet package in all the app projects because some platforms have different implementations to take advantage of platform features. Think of .NET Standard as a subset of all the platform APIs - this is why SkiaSharp works just fine for some platforms. However, Android and iOS have a different implementation to take advantage of platform features.
Although you aren't doing Android development directly (since you are using Xamarin.Forms) you wouldn't have noticed something. If you JUST include the .NET Standard package, you get the basic SkiaSharp that can, for example, convert between a Xamarin.Forms color and a SkiaSharp color. However as a result of including the package in the android app, you can additionally convert from an Android color to a SkiaSharp color.
Personally, I always include all the NuGets into the app projects just to be safe.
Here are some docs that may help you:
https://learn.microsoft.com/en-us/dotnet/standard/net-standard
I made a simple Xamarin cross-platform sqlite application for Android and IOS. I want to add Universal Windows Phone version too. To do that i followed this steps. I installed SQLite.Net-PCL from nuget manager. But i still need to write something for sqlite connection. In this link, at step 6 there is code for this but its for windows phone 8. Can you please help me?
Xamarin.Forms supports database-driven applications using the SQLite database engine, which makes it possible to load and save objects in shared code.
Xamarin.Forms applications can use the SQLite.NET PCL NuGet package to incorporate database operations into shared code by referencing the SQLite classes that ship in the NuGet. Database operations can be defined in the Portable Class Library (PCL) project of the Xamarin.Forms solution, with platform-specific projects returning a path to where the database will be stored.
But i still need to write something for sqlite connection. In this link, at step 6 there is code for this but its for windows phone 8. Can you please help me?
Windows 10 Universal Windows Platform (UWP)
Add the SQLite-net PCL NuGet to the UWP project by right-clicking and choosing Manage NuGet Packages.
Once the reference is added, implement the IFileHelper interface using the platform-specific Windows.Storage API to determine the data file path.
using Windows.Storage;
...
[assembly: Dependency(typeof(FileHelper))]
namespace Todo.UWP
{
public class FileHelper : IFileHelper
{
public string GetLocalFilePath(string filename)
{
return Path.Combine(ApplicationData.Current.LocalFolder.Path, filename);
}
}
}
Details please reference Xamarin.Forms Local Databases. The accompanying sample application is a simple Todo-list application.
I added a project reference of my Business Logic project to my console application. I can reference the project and its classes in the code of my console application. Weirdly, when I build the project, the build fails and the classes which referenced says Type is not defined.Has anybody come across an issue like this?
You have to import name space in your console application class where you are trying to use the business logic application class.
I have selected the incorrect target framework .net framework client profile 4.0 where it should be .net framework 4. Issue rectified and now I can build the project.
I have a Solution which contains an ASP.NET Web Application project. Web Application project types can only target the full .NET Framework 4, and Visual Studio won't let you select the Client Profile.
However, my Class Library projects in that same solution allow me to target the .NET Framework 4 Client Profile.
So, should I mix targeting the Client Profile and the full framework in the same solution? Or just target the full framework for every project type in a Solution containing a Web Application project? Or does it not matter either way?
If you plan to reuse the Class Library in a WPF or WinForms app, then Client Profile is a good choice, since you are likely going to be able to set your WPF or WinForms app to use Client Profile as well. Even if your WPF or WinForms app ends up requiring the full framework, Client Profile is a subset of the full framework so it will still work just fine.
If your reuse plans on the Class Library are WebApp only or your only using a Class Library to help segment code, then the target framework is really not important.
Applications that target the .NET
Framework 4 Client Profile typically
improve the deployment experience by
having smaller download sizes and
quicker install times. An application
that targets the .NET Framework 4
Client Profile has a smaller
redistribution package that installs
the minimum set of client assemblies
on the user's computer, without
requiring the full version of the .NET
Framework 4 to be present.
If your library is general purpose and the target equipment will be installed with Client Profile Framework then prefer client profile for your library, by doing this you will have smaller installers. Web Components are not included when installed Client Profile Framework.
See: http://msdn.microsoft.com/en-us/library/cc656912.aspx