Note that there are some explanatory texts on larger screens.

plurals
  1. POEF 4.1 using custom type handling money
    primarykey
    data
    text
    <p>I have been using a custom type for Money with my POCOs and tries to insert this to my database but it is <em>implicitly</em> thrown away by Entity Framework.</p> <p>This is my code made simple;</p> <p>My type;</p> <pre><code>public struct Money { private static decimal _value; public Money(Decimal value) { _value = value; } public static implicit operator Money(Decimal value) { return new Money(value); } public static implicit operator decimal(Money value) { return _value; } } </code></pre> <p>My object;</p> <pre><code>public class MyObject { [Key] public int Id { get; set; } public Money MyMoney { get; set; } } </code></pre> <p>My context;</p> <pre><code>public class Data : DbContext { public Data() : base("Data Source=.;Database=MyTest;Integrated Security=True") {} public DbSet&lt;MyObject&gt; MyObject { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity&lt;MyObject&gt;() .Property(p =&gt; p.MyMoney).HasColumnName("MyMoney"); } } </code></pre> <p>When I use this code I get the following error.</p> <blockquote> <p>The property 'MyMoney' is not a declared property on type 'MyObject'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.</p> </blockquote> <p>I guess the problem is the last sentence.... Then, what is a valid primitive property? Is there any other way to take care of this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload