Ticket_ID (PK, int, not null)
Affected_User_SID (FK, binary(28), null)
Create_Date (smalldatetime, not null)
Title (varchar(255), not null)
Message (varchar(8000), not null)
Ticket_Type (FK int, not null)
User_Names:
User_SID (PK, binary(28), not null)
First_Name (varchar(20), not null)
Last_Name (varchar(20), not null)
Email (varchar(100), null)
Phone_Number (varchar(20), null)
I'm trying to use Entity Framework to display the ticket and user information in a gridview using EntityDataSource:
Despite using the include, no data is populated in my gridview when I put Eval("User_Names.Name") on a label in a itemtemplate following other examples I have seen here.
I tried another table (ticket_type) which used a FK that was int and that table info (ticket_type.name) worked. I am using EF 4.3. Are binary fks broken in this version still?
Despite using the include, no data is populated in my gridview when I put Eval("User_Names.Name") on a label in a itemtemplate following other examples I have seen here.
Please show us how you've done to aspx codes with the EntityFramework……
I'm having the exact same problems. Entities that are related by a int foreign key, allways get results, but using varchar or nvarchar as the primary key, sometimes give results, other times no.
In the database if a do a query, i get no problem.
Is this a entity framework bug? Or has something to do with collations conflit?
In my case I had database tables that were using SIDs (from Active Directory - objectSID), I had to change the table and add another column lookup using the objectGUID and the guid works with Entity Framework.
You can also try using the master.dbo.fn_varbintohexstr / master.dbo.fn_varbintohexsubstring functions in SQL Server to convert your columns to text and use that inside a view? (performance might be bad in a view though, or you can just add a new column
and update it using those SQL Server functions)
Frankly, they should just fix the bug in EF, but you might use this as a work around.
I didn't design my table structure, but have to live with it. :/ Unfortunately EF doesn't work with binary keys or I would be able to move to it when upgrading programs.
Good luck!
Marked as answer by Thavious on Sep 27, 2012 06:01 PM
Entity Framework 4 Beta 2: Support for Binary Keys: The EF now allows you to have binary property types (and varbinary storage columns) mapped as Entity Key / Foreign Key.
Thavious
0 Points
5 Posts
Entity Framework and Binary Foreign Keys broken?
Jul 06, 2012 03:14 PM|LINK
I have 2 tables: Tickets and User_Names
Tickets:
Ticket_ID (PK, int, not null)
Affected_User_SID (FK, binary(28), null)
Create_Date (smalldatetime, not null)
Title (varchar(255), not null)
Message (varchar(8000), not null)
Ticket_Type (FK int, not null)
User_Names:
User_SID (PK, binary(28), not null)
First_Name (varchar(20), not null)
Last_Name (varchar(20), not null)
Email (varchar(100), null)
Phone_Number (varchar(20), null)
I'm trying to use Entity Framework to display the ticket and user information in a gridview using EntityDataSource:
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=HelpDeskEntities"
DefaultContainerName="HelpDeskEntities"
EntitySetName="Tickets"
Include="User_Names"></asp:EntityDataSource>
Despite using the include, no data is populated in my gridview when I put Eval("User_Names.Name") on a label in a itemtemplate following other examples I have seen here.
I tried another table (ticket_type) which used a FK that was int and that table info (ticket_type.name) worked. I am using EF 4.3. Are binary fks broken in this version still?
cornball76
Participant
1126 Points
210 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Jul 06, 2012 04:41 PM|LINK
Did you confirm in your edmx that the foreign key relationship exists for that table?
Thavious
0 Points
5 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Jul 06, 2012 08:19 PM|LINK
Yep
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Jul 09, 2012 01:29 AM|LINK
Please show us how you've done to aspx codes with the EntityFramework……
Reguards!
david_carpin...
Member
6 Points
3 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 09:49 AM|LINK
Hi thavious,
I'm having the exact same problems. Entities that are related by a int foreign key, allways get results, but using varchar or nvarchar as the primary key, sometimes give results, other times no.
In the database if a do a query, i get no problem.
Is this a entity framework bug? Or has something to do with collations conflit?
Thavious
0 Points
5 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 12:06 PM|LINK
It's a bug in Entity Framework, it can't handle binary fields used as keys.
david_carpin...
Member
6 Points
3 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 01:05 PM|LINK
Thank you thavious. This is a very bad news for me, since the project is already in production. I'l have to find an alternative.
Once again thank you.
Thavious
0 Points
5 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 04:07 PM|LINK
In my case I had database tables that were using SIDs (from Active Directory - objectSID), I had to change the table and add another column lookup using the objectGUID and the guid works with Entity Framework.
You can also try using the master.dbo.fn_varbintohexstr / master.dbo.fn_varbintohexsubstring functions in SQL Server to convert your columns to text and use that inside a view? (performance might be bad in a view though, or you can just add a new column and update it using those SQL Server functions)
Frankly, they should just fix the bug in EF, but you might use this as a work around.
I didn't design my table structure, but have to live with it. :/ Unfortunately EF doesn't work with binary keys or I would be able to move to it when upgrading programs.
Good luck!
david_carpin...
Member
6 Points
3 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 04:27 PM|LINK
Thanks. I'll give it a try.
RichardD
Contributor
3950 Points
549 Posts
Re: Entity Framework and Binary Foreign Keys broken?
Sep 27, 2012 06:34 PM|LINK
It certainly looks like it should be supported:
http://blogs.msdn.com/b/adonet/archive/2009/10/19/vs2010-and-net-framework-beta-2-announced.aspx
If it doesn't work, have you reported it on Connect?