JonPSmith / EfCore.TestSupport

Tools for helping in unit testing applications that use Entity Framework Core
https://www.thereformedprogrammer.net/new-features-for-unit-testing-your-entity-framework-core-5-code/
Other
352 stars 53 forks source link

Mapping to Views #36

Closed LouisMilesRH closed 3 years ago

LouisMilesRH commented 4 years ago

Hi Jon,

This is probably more of a feature request than issue but is there a way to get the CompareEFWithDB Method to check for Views as well as tables. EF Core doesn't actually care which you use and it can be especially useful when wanting to get data from other databases or linked servers, where a table would not be appropriate.

It would also need the issue with missing Primary Keys to be solved however (issue #32 ) as obviously the view does not have a Primary Key associated with it.

Worth noting that you can work around this by both including the View in TablesToIgnoreCommaDelimited and then subsequently also adding the error string "NOT IN DATABASE: Entity 'XXXXX', table name. Expected = XXXXView" but it's a bit messy!

Any help would be greatly appreciated as have been really loving this library so far :)

Many thanks, Louis

JonPSmith commented 4 years ago

Hi @LouisMilesRH,

I have thought about Views but the EfSchemaCompare code is really complex and takes a LOT of work keeping it up to date. I'll put it on the list of ideas but I need to think how it would work. I assume you have classes mapped to the Views by EF Core, otherwise this won't work.

I'm currently really busy updating my EF Core book to NET Core 5 so I won't get to look at this for a while.

I'm pretty busy at the moment.

LouisMilesRH commented 4 years ago

Yeah totally understandable - it's a very very clever library. As I say my current work around works fine it's just slightly clunky.

Maybe a temporary fix could be to add an easier way to just exclude the view from the errors (so basically wrap my work around code above into one function call). Appreciate it's the same under the hood but would make my test look a lot neater :)

I do think the null reference caused by no primary key is a bigger "gotcha" so would probably prioritise that one.

Definitely interested in your new book - the last one was very helpful! Will check it out!

JonPSmith commented 4 years ago

I have just release 3.2.0, which has a fix for issue #32. Have a go and let me know.

LouisMilesRH commented 4 years ago

3.2 working great for me - I no longer getting the null reference error on tables 👍

Regarding this issue however, in order to get views to work I still needed to to ignore the view and add the ignore error string as per my comments above. This is a good enough work around for now however so would still class this issue as a "nice to have", but would understand if the complexity outweighs the benefit.

JonPSmith commented 3 years ago

Hi @LouisMilesRH ,

Long time since you asked about Views, but I have finally got around to EfSchemaCompare and I have added checking of SQL Views. I don't know if your still using EfSchemaCompare, but if you are then the EfSchemaCompare is now in its own EfCore.SchemaCompare project (documentation in the Readme.md file).

I have just releases Version 5.0.0, which only works with EF Core 5.1, to NuGet. If you can give it a proper test on your database that would be great.

PS. I am updating all my libraries to handle EF Core 5 now that I have written the bulk of my book, Entity Framework Core in Action, just a ton of review feedback to go through.

LouisMilesRH commented 3 years ago

Oh that's great :) still very much using EFSchemaCompare - have found it to be an excellent tool and fits our development cycle really well. Will definitely be checking this out more thoroughly over the coming weeks!!

Really appreciate the update and look forward to the book being completed.

L


From: Jon P Smith notifications@github.com Sent: 2 Jan 2021 10:02 To: "JonPSmith/EfCore.TestSupport" EfCore.TestSupport@noreply.github.com Cc: Louis Miles Louis.Miles@rawlinson-hunter.com; Mention mention@noreply.github.com Subject: Re: [JonPSmith/EfCore.TestSupport] Mapping to Views (#36)

Hi @LouisMilesRHhttps://github.com/LouisMilesRH ,

Long time since you asked about Views, but I have finally got around to EfSchemaCompare and I have added checking of SQL Views. I don't know if your still using EfSchemaCompare, but if you are then the EfSchemaCompare is now in its own EfCore.SchemaComparehttps://github.com/JonPSmith/EfCore.SchemaCompare project (documentation in the Readme.md file).

I have just releases Version 5.0.0, which only works with EF Core 5.1, to NuGethttps://www.nuget.org/packages/EfCore.SchemaCompare. If you can give it a proper test on your database that would be great.

PS. I am updating all my libraries to handle EF Core 5 now that I have written the bulk of my book, Entity Framework Core in Actionhttps://bit.ly/EfCoreBookEd2, just a ton of review feedback to go through.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/JonPSmith/EfCore.TestSupport/issues/36#issuecomment-753454346, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOHV3ZQQAWHUG7XDBY2SUMTSX3VEFANCNFSM4NGBSPAA.

Rawlinson & Hunter LLP - Caution & Information

From 1st April 2020 (the "Transfer Date)", the general partnership known as Rawlinson & Hunter (the "Partnership") transferred its business to a limited liability partnership called Rawlinson & Hunter LLP (the "LLP"). The Partnership ceased trading on that date, and the LLP has replaced the Partnership and its partners as the provider of professional services under the name 'Rawlinson & Hunter' in relation to both existing and new matters. No individual member, employee or consultant of the LLP will have any personal liability to you for the professional services provided to you after the Transfer Date, even if that individual is described as a 'partner', as those services are being provided by the LLP.

By responding to this e-mail or continuing to instruct or engage or communicate with us you acknowledge that the LLP (and not the Partnership) has been acting, and will continue to act, for you with effect from the Transfer Date.

This email is confidential and for the addressee only. Any unauthorised dissemination of its contents is prohibited and may be illegal. Attachments to this email are usually sent in Microsoft Office format or Adobe PDF and are checked for viruses by Mimecast. We cannot accept liability for any damage sustained as a result of viruses. Please check upon receipt for viruses. All PDF documents should be opened using Adobe Reader to ensure the contents are displayed correctly.

Rawlinson & Hunter LLP is a limited liability partnership registered in England & Wales with registration number OC430503. Its registered office is Eighth Floor, 6 New Street Square, New Fetter Lane, London, United Kingdom, EC4A 3AQ. A list of its members is available for inspection at the registered office. Regulated for a range of investment business activities and licensed to carry out the reserved legal activity of non – contentious probate in England and Wales by the Institute of Chartered Accountants in England and Wales. Registered with the Chartered Institute of Taxation as a firm of Chartered Tax Advisers. VAT Registration No: GB 239 2201 83. Rawlinson & Hunter is the trading name of Rawlinson & Hunter LLP and the term partner, when used in relation to Rawlinson & Hunter LLP, refers to a member of the LLP

JonPSmith commented 3 years ago

Glad to hear its useful. If you have a problem or suggestion then raise a issue on the new project, but if its a "It works" then just add to this issue.