I red this article: The entity cannot be constructed in a LINQ to Entities query , but guess it's not fully related to my issue.
I have this code:
public class Class1
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
}
[Table("Class2")]
public class Class2
{
[Key]
[Column("Prop1")]
public string Prop1 { get; set; }
[Column("Prop2")]
public string Prop2 { get; set; }
[Column("Prop3")]
public string Prop3 { get; set; }
}
and method edit where I want to use these ones:
using (var data = new Context())
{
var config = data.Class2.FirstOrDefault(c => c.Prop1.Contains(some_string));
if (config != null)
{
config.Prop1 = class1_instance.Prop1;
config.Prop2 = class1_instance.Prop2;
config.Prop3 = class1_instance.Prop3;
}
data.Entry(config).State = EntityState.Modified;
data.SaveChanges();
}
So what I want to get is simplify editing, instead of assigning each property one by one I want to write something like config = class1_instance;
So I've inherited Class1
from Class2
, but getting
System.NotSupportedException
(the entity or complex type "Class1" cannot be constructed in a Linq to Entities query).
How can I handle it?