I'm trying to figure out how to use a NotMapped property with OData
I have this User Model:
[DataContract]
public class User
{
[DataMember]
public long Id { get; set; }
[DataMember]
public virtual InstagramUser InstagramUser { get; set; }
[DataMember]
public virtual FacebookUser FacebookUser { get; set; }
[NotMapped]
public string InstagramID { get; set;
}
And I have this GetAll() method in the User Controller
public IQueryable<User> GetAllUsers()
{
_repository = new UserRepository();
return _repository.GetAll().AsQueryable();
}
and this GetAll() function in the User repository
public IQueryable<User> GetAll()
{
InstaStoryDB db = new InstaStoryDB();
var ret = db.Users.Include("InstagramUser").Include("FacebookUser").AsQueryable();
foreach(User user in ret)
{
user.InstagramID = user.InstagramUser.InstagramID; //<-- I'm adding here the value to the property
}
return ret;
}
And this is the InstagramUser Model
[DataContract]
public class InstagramUser
{
[DataMember]
public long UserId { get; set; }
[DataMember]
public string InstagramID { get; set;
}
All Working good.
I did a change to the User model and added the InstagramUser
that contain the InstagramID
, so I added [NotMapped] attribute to remove the InstagramID from the User table in the DB since the InstagramUser already contain the InstagramID.
When ever I try to use Odata like this: localhost:555/api/users/?$filter=InstagramID eq '456456546' It's failed and return an error that the InstagramID property is not exist.
what can I do to use filter with Odata on NotMapped property?
NotMapped
property.NotMappet
property is not described in your model and so it is not available for querying when you use EF provider for OData service. – Ladislav Mrnka