none
How to create a custom view in Conceptual model in Entity framework 5 RRS feed

  • Question

  • Is there any way to create a custom view in EF5 , which will not be created in database but only in model.

    In  Detail, An Entity(View) created in EF5 using designer, which is mapped to different entities in storage model, and only kept in Application side not in DB

    For eg:

    CustomEntity1(not a view created in DB) mapped to tables(Entity1, Entity2, Entity3).

    • Moved by Vicky SongMicrosoft employee Wednesday, December 19, 2012 2:22 AM (From:Visual Studio Database Development Tools (Formerly "Database Edition Forum"))
    Tuesday, December 18, 2012 4:14 AM

All replies

  • Hi Antony,

    I am moving your issue to the ADO.NET Entity Framework and LINQ to Entities  forum so that you can get better support there.

    Thanks.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 2:21 AM
  • Hi Antony,

    For custom view, I think it is not possible to create in model without creating in database, because the tables/views in SSDL are required to be mapped to tables/views in database. If the database does not have the corresponding tables/views, the related SQL scripts generated by EF will encounter an exception. For your requirement, I recommend you use linq to entites query. If you want to create a dynamic condition for linq to entities, you can use compiled query: http://msdn.microsoft.com/en-us/library/bb896297.aspx

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 8:08 AM
  • Hi Alexandar,

    Thanks for your reply,

    In CompiledQuery, we have to write linq query and there is no UI to define the so called view. 

    The same can be achieved using Defining Queries, But if we try to update model from DB, the same will be lost. Also to achieve it we should write query in xml file(.edmx). So it is not feasible for our criteria.

    I think more feasible way is using 'Mapping an entity to multiple tables'. But to acheve the same using mapping, I have to remove one of the tables from conceptual model, if not it will result in multiple entity mapping issue to same table.

    Is there any way to map TWO conceptual model entity to same table in Storage model.

    Regards.

    Wednesday, December 19, 2012 9:30 AM
  • Hi,

    I am not sure what means "there is no UI to define". If you have any problem in writing Linq query, you can post here and maybe members can help.

    Monday, December 24, 2012 7:32 AM
  • Hello ,

    Thanks you for your kind reply,

    I don't have any problem to write LINQ query. And thanks for the help you offered.

    But my query is, If we have one designer, which is already equipped with mapping, entity/Table splitting, association/Inheritance manipulation, Updating Database from Model and Model from Database and lots more.... ,then why don't have support for custom view creation. I think the IDE's whatever it may be are used for minimizing the effort of developer from writing code. * In that case, Writing query from code behind for customization and using designer to design the same what I designed in SQL server management studio sounds awkward. *

    If there is any other way than writing query either in xml page(edmx) or in code behind, please suggest me.

    If not, whoever it may concern, please consider it for future release of EF. and I think this is the one of the basic requirement.

    Monday, December 24, 2012 10:18 AM