Error when using InverseProperty?
Posted: Fri 06 Jan 2012 21:43
Using dotConnect with Entity Framework Code First I get an error when trying to walk up a relationship to a parent table.
I have an Account table and a Request table. The request table has let's say CreatedBy and ModifiedBy on it. On the Account entity I have an ICollection RequestsCreatedByMe and an ICollection RequestsModifiedByMe. The collections are annotated with [InverseProperty("CreatedBy")] and [InverseProperty("ModifiedBy")]
See below for tables and objects, but when I execute the following code:
_context.Accounts.Where(a => a.RequestsCreatedByMe.Any())
in order to get all accounts that have requests created the sql generated is bad:
SELECT
"GroupBy1".A1 AS C1
FROM ( SELECT Count(1) AS A1
FROM ADME.ACCOUNT "Extent1"
WHERE EXISTS (SELECT
1 AS C1
FROM ADME.REQUEST "Extent2"
WHERE "Extent1".ID = "Extent2"."Account_ID"
)
) "GroupBy1"
Clearly the code should have been "Extend2"."CreatedByID" as that is what I stated to use in the InverseProperty and the Account_ part is completely bogus. Am I missing something or is this a bug?
Tables:
CREATE TABLE Account (ID INT, Name NVARCHAR2(200));
CREATE TABLE Request (ID INT, CreatedByID INT, ModifiedByID INT);
INSERT INTO ACCOUNT VALUES (1,'Foo');
INSERT INTO ACCOUNT VALUES (2, 'Bar');
INSERT INTO Request VALUES (1, 1, 2);
INSERT INTO Request VALUES (2, 2, 1);
INSERT INTO Request VALUES (3, 2, 1);
INSERT INTO Request VALUES (4, 2, 1);
Classes:
[Table("ACCOUNT", Schema = "MYSCHEMA")]
public class Account
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
[InverseProperty("CreatedByID")]
public virtual ICollection RequestsCreatedByMe { get; set; }
[InverseProperty("ModifiedByID")]
public virtual ICollection RequestsModifiedByMe { get; set; }
}
[Table("REQUEST", Schema="MYSCHEMA")]
public class Request
{
[Key]
public int ID { get; set; }
public int CreatedByID { get; set; }
public virtual Account CreatedBy { get; set; }
public int ModifiedByID { get; set; }
public virtual Account ModifiedBy { get; set; }
}
I have an Account table and a Request table. The request table has let's say CreatedBy and ModifiedBy on it. On the Account entity I have an ICollection RequestsCreatedByMe and an ICollection RequestsModifiedByMe. The collections are annotated with [InverseProperty("CreatedBy")] and [InverseProperty("ModifiedBy")]
See below for tables and objects, but when I execute the following code:
_context.Accounts.Where(a => a.RequestsCreatedByMe.Any())
in order to get all accounts that have requests created the sql generated is bad:
SELECT
"GroupBy1".A1 AS C1
FROM ( SELECT Count(1) AS A1
FROM ADME.ACCOUNT "Extent1"
WHERE EXISTS (SELECT
1 AS C1
FROM ADME.REQUEST "Extent2"
WHERE "Extent1".ID = "Extent2"."Account_ID"
)
) "GroupBy1"
Clearly the code should have been "Extend2"."CreatedByID" as that is what I stated to use in the InverseProperty and the Account_ part is completely bogus. Am I missing something or is this a bug?
Tables:
CREATE TABLE Account (ID INT, Name NVARCHAR2(200));
CREATE TABLE Request (ID INT, CreatedByID INT, ModifiedByID INT);
INSERT INTO ACCOUNT VALUES (1,'Foo');
INSERT INTO ACCOUNT VALUES (2, 'Bar');
INSERT INTO Request VALUES (1, 1, 2);
INSERT INTO Request VALUES (2, 2, 1);
INSERT INTO Request VALUES (3, 2, 1);
INSERT INTO Request VALUES (4, 2, 1);
Classes:
[Table("ACCOUNT", Schema = "MYSCHEMA")]
public class Account
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
[InverseProperty("CreatedByID")]
public virtual ICollection RequestsCreatedByMe { get; set; }
[InverseProperty("ModifiedByID")]
public virtual ICollection RequestsModifiedByMe { get; set; }
}
[Table("REQUEST", Schema="MYSCHEMA")]
public class Request
{
[Key]
public int ID { get; set; }
public int CreatedByID { get; set; }
public virtual Account CreatedBy { get; set; }
public int ModifiedByID { get; set; }
public virtual Account ModifiedBy { get; set; }
}