It would be nice to EF be able to define a View and not only tables.
To do that, right now I have a table and will be droped in the Seed method of the configuration and a view with the same name will be created.
context.Database.ExecuteSqlCommand("IF EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID(N'[dbo].[vwUserTypes]')) DROP TABLE [dbo].[vwUserTypes]");
context.Database.ExecuteSqlCommand(@"CREATE VIEW [dbo].[vwUserTypes] AS SELECT TOP (100) PERCENT ReferenceId AS UserTypeId, ReferenceValue AS UserType FROM dbo.tblSystemReferences WHERE (ReferenceTable = 'UserType') AND (IsActive = 1) ORDER BY UserTypeID");
Doing this will work fine but if I want to create a relation between this view and tblUser table the system said that cannot create the FK in the view.
What I expect it's possible to mark my domain object to be serializes as a view and somewhere and somehow I could create a linq query to define my view or even SQL Statement like I do now in my example.
In the end, if I want to link a object to this View, the EF will not create a FK in the View.
is the future, base on a method would be nice to generate the store procedure code too ... but that's another story.
Regards
Paulo Aboim Pinto
Odivelas - Portugal
Comments: Hello, I don't think this is a close issue because we have a workarround. You say that we cannot create FK and the main goal of this issue it's to be able to use the entity in our code as we want without the necessity to create extra object (usual's DTO) to combine object that will be serialize as tables ans views. I'm using this strategy and it's very painful and should be EF responsibility to provide it. Don't you agree? regards Paulo Aboim Pinto
To do that, right now I have a table and will be droped in the Seed method of the configuration and a view with the same name will be created.
context.Database.ExecuteSqlCommand("IF EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID(N'[dbo].[vwUserTypes]')) DROP TABLE [dbo].[vwUserTypes]");
context.Database.ExecuteSqlCommand(@"CREATE VIEW [dbo].[vwUserTypes] AS SELECT TOP (100) PERCENT ReferenceId AS UserTypeId, ReferenceValue AS UserType FROM dbo.tblSystemReferences WHERE (ReferenceTable = 'UserType') AND (IsActive = 1) ORDER BY UserTypeID");
Doing this will work fine but if I want to create a relation between this view and tblUser table the system said that cannot create the FK in the view.
What I expect it's possible to mark my domain object to be serializes as a view and somewhere and somehow I could create a linq query to define my view or even SQL Statement like I do now in my example.
In the end, if I want to link a object to this View, the EF will not create a FK in the View.
is the future, base on a method would be nice to generate the store procedure code too ... but that's another story.
Regards
Paulo Aboim Pinto
Odivelas - Portugal
Comments: Hello, I don't think this is a close issue because we have a workarround. You say that we cannot create FK and the main goal of this issue it's to be able to use the entity in our code as we want without the necessity to create extra object (usual's DTO) to combine object that will be serialize as tables ans views. I'm using this strategy and it's very painful and should be EF responsibility to provide it. Don't you agree? regards Paulo Aboim Pinto