1

I am getting an error while fetching data from db.The error is like this:-

{"Invalid column name 'Amount_Value'.\r\nInvalid column name 'Amount_Currency'.\r\nInvalid column name 'Amount_Value'.\r\nInvalid column name 'Amount_Currency'."}

Here is my main model of "Deals":-

public class Deal {

   public long ID { get; set; }

   [StringLength(1024),Required]
    public string Title { get; set; }

   public Client Party { get; set; }
   public long PartyID { get; set; }


   public DateTime Created { get; set; }
   public long Version { get; set; }

   [DataType(DataType.MultilineText)]
   public string Notes { get; set; }

   public Money Amount { get; set; }
   public DealKindEnum Mode { get; set; }
  }

Here "Money" is another class which is like this:-

public class Money
{
 [DataType(DataType.Currency)]
 public double Value { get; set; }
 public string Currency { get; set; }
}

I am getting error while using this query:--

var query = from client in db.Clients
 join ra in db.Deals on client.ID equals ra.PartyID
 where (ra.ID == id || id == 0)
 select ra;
1
  • So Money is not an Entity => doesn't exist in db ? If it is, I think your property should be virtual. public virtual Money Amount {get;set;} If it's not, you should mark with NotMappedAttribute ([NotMapped] on property) Commented Apr 2, 2014 at 12:40

1 Answer 1

1

EF can't do anything with properties which are not in database. From your comment, Money is not an entity.

So you have to mark the property in Deal class as NotMapped

[NotMapped]
public Money Amount { get; set; }

And EF won't try to get anything from db while querying. Of course, you won't have anything in Amount property, but how could you if it's not in db...

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks it worked and please see my another question which I edited in this question only.
@AkankshaT you should rather let your question as it was and ask a new one. Or anyone looking at this one won't understand anything !
Sorry.I am doing that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.