Search code examples
windows-phone-8data-annotations

How to change targetframework WP81 app


I have a Windows Phone 8.1 app in VS2015.

I am trying to add a property to my model that is not saved to the database. However, when I try to use the [NotMapped] annotation, I get the error:

  The type or namespace name 'NotMapped' could not be found

I then added this using statement and tried to add it as a reference to the project. But apparently, I need to change my targetFramework in order to use this reference.

using System.ComponentModel.DataAnnotations.Schema;

Can a WP 8.1 app use the [NotMapped] annotation like below? Or is this not allowed in a WP app?

    [NotMapped]
    public double MyColumnName { get; set; }

Solution

  • The NotMappedAttribute is not available on Windows Phone 8.1.

    Universal Windows Platform

    Available since 10

    .NET Framework

    Available since 4.5

    Source: MSDN

    As Entity Framework is not available on Windows Phone 8.1, it's no use trying to use data annotations on the client. You'll have simple DTO classes on the client and more extensive models on the server backend where data-access to your database is handled. Converting between these 2 types can be done easily with tools like AutoMapper.

    If you want to have some database on the WP client, you'll have to fall back to one of these options:

    • SQL CE
    • SQLite
    • Any other file based storage (json, xml, document based databases)