顯示具有 WPF 標籤的文章。 顯示所有文章
顯示具有 WPF 標籤的文章。 顯示所有文章

2021/11/1

visual studio 2019 新增oracle 連線無法使用entity framework 6

以下內容在2019上,『或許』能成功,但是很繁瑣
目前先把軟體降階到2017
到今日(2021/11/15)有VS2022,但是oracle 的ODP .Net還沒有推出
等有oracle for 2022的再來測試

在選擇entity framewark 的地方,就是一直反灰,無法使用
提示『XXXX找不到資料庫提供者XXXX'
甚至還會在選擇entity framework 版本時,突然消失
怎麼建立都是不行
後來自己找到原因

步驟1.把CPU改成X64,然後重新開啟
步驟2.專案清除。專案重建
步驟3.把6.122.21.1改為4.122.21.1
     <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
          <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices,
                    Oracle.ManagedDataAccess.EntityFramework, Version=6.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
        </providers>



上述無效,

重新建立app,設定方式如下:

1.app.config裡面有三段,建議保留

<configSections>
    <!--<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->
    
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>


<providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=4.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>

 

<system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=6.122.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>

2.如果要用ADO.net+EF請把EF的版本改掉,由6.122.21.1,變成4.122.21.1


    Oracle.ManagedDataAccess.EntityFramework, Version=6.122.21.1, Culture=neutral,


3.執行的時候,會有異常,除了剛剛的EF變成4.122.21.1,也要把OracleClientFactory,改成4.122.21.1


    Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=6.122.21.1,

正常了


(E04,浪費了我8小時改一個數字,oracle的產品阿......)
(花了一個禮拜的時間....)

補充資訊:
有人提供方向:
https://www.facebook.com/groups/DotNetUserGroupTaiwan/posts/2768088380150929/?comment_id=2768431143449986&notif_id=1636610180937126&notif_t=group_comment&ref=notif
參考頁面
vs 2019 TNS_ADMIN 

 

VS 2019內,建議還是設定好TNS_ADMIN
 在VS選單列,Tools->Options->Oracle Developer Tools ->Connection Configuration

補充:重新閱讀下面內容

https://blog.darkthread.net/blog/managed-odp-net

發現一個問題,關鍵在這一段

注意:Managed ODP.NET支援Entity Framework,但不提供設計階段支援,如果想在Visual Studio使用Entity Framework專案項目,仍須安裝32位元版ODAC with Oracle Developer Tools for Visual Studio,另一方面,開發者通常會用到SQL Plus或第三方Oracle資料庫工具,故開發環境仍會以ODAC 32位元為主,伺服器或大量部署的客戶端才是Managed ODP.NET展現威力的主戰場。

所以,我之前一直有亂七八糟問題,還是要改6->4

但是我還是要『另外安裝』這個『ODAC with Oracle Developer Tools for Visual Studio』

我才能用EF的功能

(oracle的產品阿......)

2018/9/19

Page和UserControl的區別


中文來源:
http://blog.163.com/liulei0729@126/blog/static/32530612201211362532114/

 Page 是從 UserControl 繼承的,首先就有著「is a UserControl」 的關係;
Page 封裝了對 Frame 的導航,這也是 Page 的最大特點和職責,而 UserControl 沒有這個職責。

因為 UserControl 從 UIElement 繼承,這樣就導致了 UserControl 可以用在 
  this.RootVisual = userControl ;
  Grid.Children.Add( userControl );
  等等地方使用(其效果往往就是使UserControl呈現在界面上),而由於「Page is a UserControl」 ,這就往往讓人搞不清楚是要使用Page還是UserControl。在使用場合上,個人認為是顧名思義就可以了,如果你用過 ASP.NET ,那麼 Page 就相當於是一個個的 .aspx 頁面,而 UserControl 則是 .aspx 中使用的自定義控件。
如果要找更完整的
stackoverflow
https://stackoverflow.com/questions/12206120/window-vs-page-vs-usercontrol-for-wpf-navigation

A Window object is just what it sounds like: its a new Window for your application. You should use it when you want to pop up an entirely new window. I don't often use more than one Window in WPF because I prefer to put dynamic content in my main Window that changes based on user action.
A Page is a page inside your Window. It is mostly used for web-based systems like an XBAP, where you have a single browser window and different pages can be hosted in that window. It can also be used in Navigation Applications like sellmeadog said.
A UserControl is a reusable user-created control that you can add to your UI the same way you would add any other control. Usually I create a UserControl when I want to build in some custom functionality (for example, a CalendarControl), or when I have a large amount of related XAML code, such as a View when using the MVVM design pattern.
When navigating between windows, you could simply create a new Window object and show it
var NewWindow = new MyWindow();
newWindow.Show();
but like I said at the beginning of this answer, I prefer not to manage multiple windows if possible.
My preferred method of navigation is to create some dynamic content area using a ContentControl, and populate that with a UserControl containing whatever the current view is.
<Window x:Class="MyNamespace.MainWindow" ...>
    <DockPanel>
        <ContentControl x:Name="ContentArea" />
    </DockPanel>
</Window>
and in your navigate event you can simply set it using
ContentArea.Content = new MyUserControl();
But if you're working with WPF, I'd highly recommend the MVVM design pattern. I have a very basic example on my blog that illustrates how you'd navigate using MVVM, using this pattern:
<Window x:Class="SimpleMVVMExample.ApplicationView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SimpleMVVMExample"
        Title="Simple MVVM Example" Height="350" Width="525">

   <Window.Resources>
      <DataTemplate DataType="{x:Type local:HomeViewModel}">
         <local:HomeView /> <!-- This is a UserControl -->
      </DataTemplate>
      <DataTemplate DataType="{x:Type local:ProductsViewModel}">
         <local:ProductsView /> <!-- This is a UserControl -->
      </DataTemplate>
   </Window.Resources>

   <DockPanel>
      <!-- Navigation Buttons -->
      <Border DockPanel.Dock="Left" BorderBrush="Black"
                                    BorderThickness="0,0,1,0">
         <ItemsControl ItemsSource="{Binding PageViewModels}">
            <ItemsControl.ItemTemplate>
               <DataTemplate>
                  <Button Content="{Binding Name}"
                          Command="{Binding DataContext.ChangePageCommand,
                             RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                          CommandParameter="{Binding }"
                          Margin="2,5"/>
               </DataTemplate>
            </ItemsControl.ItemTemplate>
         </ItemsControl>
      </Border>

      <!-- Content Area -->
      <ContentControl Content="{Binding CurrentPageViewModel}" />
   </DockPanel>
</Window>

Screenshot1 Screenshot2

如果還是不懂,還有日文版
https://qiita.com/nie/items/3e2f6f37b3425585952b

意外と説明しているところが無かったので
WPF Window
獨立して表示可能な存在、PageやUserControlのホストになる存在。
WPF Page
ホスト下で表示し、「進む」「戻る」などのナビゲーションアプリケーションでの使用を前提とした使い方。
ホストで使用するにはフレームコントロールを経由して使います。
WPF UserControl
コントロールを自作します。これ単體では獨立して動作せず、Window內に設置する必要があります。
自作した後、一度プロジェクトをビルドしないとコントロールを設置出來ません。
自作コントロールの使い方は通常コントロールと使用方法は同じです。
コントロールに固有名詞を設定すれば、メインウィンドウからメソッドの呼び出しも可能です。
例:自作コントロールに固有名詞 MyControlを設定
自作コントロール內部のメソッド
        void DoWork()
        {
        ///自作コントロールに実行させたい挙動
        }
メインウィンドウからボタンを押すと、MyControl內の DoWorkメソッドを実行する場合
メインウィンドウからボタンを押すと、自作コントロール內のメソッドを呼び出す
        private void Button_Click(object sender, RoutedEventArgs e)
        {
         MyControl.DoWork();
        }
メインウィンドウとは無関係に、自作コントロール內のボタンを押した場合の挙動は、自作コントロール側に挙動を書き込みます。
これは深いことを考えず、ウィンドウにボタンを設置してその挙動を書く時のコードと同じです。

手機QQ禁用NFC

一圖解千言萬語 應用程式權限:透過NFC起動