How to relate a SQL based entity with an Object based entity in Entity Framework

  • Thread starter Thread starter markla
  • Start date Start date
M

markla

Hi,

I have an Entity data model built in Entity Framework, which sources data
primarily from an MS SQL 2008 database, and sources some static (data
dictionary) values from code-based objects. I know I *could* store the data
dict values in SQL: for various reasons that's not the path I want to take.

I have some lookups, which are based on code-based Objects. They are
encapsulated in Objects because the values can change during processing, and
are not persisted to the database, and they derive from "EntityObject" so
they are EF-ready.

For example, I may have an EF object "Event", and an Object type
"EventType". Event is stored in the database, however EventType is loaded
depending on what types I support in an application variant (depending on
DLLs loaded).

In looking at the edmx file and other info, I can't see how to mix SQL and
Non-SQL Object based entities.

How can I create an EF relation between the SQL based "Event", and an Object
based "EventType"?

Thanks in advance for assistance,
+Mark
 
Hi Markla,

As for "mixing the SQL and Non-SQL. object entities", here are some of my
understanding and suggestion.

The ADO.NET entity framework and EDM mainly focus on the object mapping
between code level and backend database source. So generally, the current
tool and IDE support will focus on generating the database to class
mapping. For your scenario that you want to extend the entities so as to
support some class/objects mapping to non-database source, I think you can
just add a partial class code file to extend the generated entity
classes(from database). For example, if you want the main "xxxxxEntity"
class contains some methods which query a file or calcuate via algorithm on
the fly, you can add a custom method for the class in that partial class
file.

#Customizing Objects (Entity Framework)
http://msdn.microsoft.com/en-us/library/bb738612.aspx

If you want to add not only custom functionality(methods), but also classes
that do not directly mapping to any database table, I'm afraid you need to
maintain those classes yourself in different source code file. However ,I
think it is still quite convenient for you to use them together via LINQ
(linq to entity + linq to objects).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
Back
Top