ADO.NET Entity Framework閉じる

ページコードでリクエストを書く人は専用です...


すべての人に挨拶!



VisualStudio 2008の次のバージョンにはADO.NET EntityFrameworkが追加されるというハブに関する情報が少しあります。 (秘密をお伝えします、このバージョンはすでに登場しています。)この開発は、マウスを数回クリックするだけでプロジェクトのデータロジックを作成できるユニバーサルフレームワークです。

これまで、datalogicsを使用して、2種類のプロジェクトに出会いました。 最初のものは悪名高いNHibernateフレームワークで作成され、他のものはプログラマーによって実装されました。 3年間、私はさまざまなシステムを作成および開発してきましたが、今回はペンのみでデータを操作するロジックを開発してきました。

そして先日、新しいWindowsをインストールした後、VisualStudio WebDeveloper Expressをダウンロードし、喜んでパッケージにADO.NET EntityFrameworkを見つけました。 しばらくして、ドメインを登録し、簡単なサイトを作成し、このフレームワーク用のプログラムを書く力を鍛え始めました。





ADO.NET EFの記事のほとんどが焦点が絞られていることに少し不愉快な驚きを覚えました。 データベースを適切に構成し、エンティティを作成し、これらのエンティティに対して基本的なアクションを実行する方法に関する最初から最後までの完全な情報を見つけることは不可能でした。 ほとんどの記事は、これらのトピックの1つのみをカバーしています。 まあ、勉強しながら、私はあなたと経験を共有することにしました%ユーザー名%。 同時に、私のコードを使用して、ビジネスプロセスを操作するシステムを上げることはできませんが、それでも、どちらの側からアプローチするかを理解できます。







まず、データベースを使用して簡単なWebプロジェクトを作成する必要があります。 また、データベースエクスプローラーを使用してデータベースにすぐに接続することもできます。 ちょうどそれがより便利になります。







その後、新しい「ADO.NET Entity Data Model」要素をプロジェクトに追加する必要があります。







システムは、データベースに接続するための文字列を指定する必要があり、最初のADO.NET EFモデルがどこから来るかを示す必要があります。







私のデータベースには、PostとUserの2つの非常に単純なテーブルが既にあるので、苦労せずに、データベースに基づいてモデルを作成しました。 これらすべての非常に簡単な手順の後、実用的なデータベースモデルを取得しました。 さらに、このモデルを視覚的に研究した後、コードを調べて、フレームワークがすべてのクラスをどのように記述するかを確認することを忘れませんでしたか?



namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  1. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  2. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  3. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  4. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  5. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  6. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  7. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  8. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  9. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  10. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  11. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  12. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  13. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  14. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  15. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  16. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  17. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  18. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  19. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  20. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  21. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  22. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  23. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  24. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  25. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  26. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  27. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  28. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  29. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  30. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



  31. namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .



namespace DataBaseCore { /// <summary> /// There are no comments for DbModel in the schema. /// </summary> public partial class DbModel : global::System.Data.Objects.ObjectContext { /// <summary> /// Initializes a new DbModel object using the connection string found in the 'DbModel' section of the application configuration file. /// </summary> public DbModel() : base ( "name=DbModel" , "DbModel" ) { this .OnContextCreated(); } /* */ [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName= "DataBaseCore" , Name= "Post" )] [global::System.Runtime.Serialization.DataContractAttribute(IsReference= true )] [global::System. Serializable ()] public partial class Post : global::System.Data.Objects.DataClasses.EntityObject { /// <summary> /// Create a new Post object. /// </summary> /// <param name="id">Initial value of Id.</param> public static Post CreatePost( int id) { Post post = new Post(); post.Id = id; return post; } * This source code was highlighted with Source Code Highlighter .







datalogicsを扱う専門家の訓練を受けた目は、かなりシンプルでエレガントなクラスの存在を示しました。これにより、システム内の投稿とユーザーの両方を扱うことができました。



まあ、まあ、私たちはすでにコードを持っています、それを使い始めるだけです。 そして、ここで、ASP.NETのすべての魅力と可能性が明らかになりました。 ページ上のかなりの数のデータソースの中で、エンティティデータソースを見ました。これは、クラスからの要求に応じてデータを提供できることを喜ばしく思っています。 フォームにドラッグアンドドロップし、セットアップウィザードを起動して、データソースを投稿テーブルにすばやくフックします。







疑う余地なく、ASPXコードでのデータ痛の説明はずっと良くなりました。





  1. < asp:EntityDataSource ID = "dsPosts" runat = "server" ConnectionString = "name = DbModel"
  2. DefaultContainerName = "DbModel" EntitySetName = "Post" >
  3. </ asp:EntityDataSource >
*このソースコードは、 ソースコードハイライターで強調表示されました。


あなたは言うことができます-優雅に輝く。



データプロバイダーがフォームに表示された後、コンシューマーも必要です。 巧妙にならずに、すべての投稿を順番に表示する単純なコードを追加しました。







  1. < asp:リピーター runat = "server" ID = "repPosts" DataSourceID = "dsPosts" >
  2. < HeaderTemplate >
  3. </ HeaderTemplate >
  4. < ItemTemplate >
  5. < div >
  6. < h3 >
  7. < asp:ラベル ID = "lblHeader" runat = "server" Text = '<%#Eval( "Header")%>' > </ asp:ラベル >
  8. </ h3 >
  9. < p >
  10. < asp:ラベル ID = "lblText" runat = "server" Text = '<%#Helpers.TypographText(Eval( "Text")。ToString())%>' > </ asp:Label >
  11. </ p >
  12. </ div >
  13. </ ItemTemplate >
  14. </ asp:リピーター >
*このソースコードは、 ソースコードハイライターで強調表示されました。




そして、ここで私の話の最も簡単な部分が終わります。 これまでは、マウスを使用してすべての操作を繰り返すことができます。 とても簡単でした。 オブジェクト指向のデータベースビューを作成し、このビューを使用して、データベースからページにデータを出力し始めました。 同時に、単一のリクエストを作成したことも、データベースから直接データを受信することもありませんでした...



しかし、データベースに何もない場合、ユーザーは何を表示する必要がありますか? 良くない データベースに入力するフォームを作成する必要があります。 次に、マウスプログラミングを終了し、コードを記述します。



システム上の投稿を操作するための2つの最も基本的なアクションを実行しました-これは追加と削除です。 このコードと類推して編集することは誰にとっても難しいことではありません。







  1. 名前空間 DBW
  2. {
  3. パブリック クラスの投稿
  4. {
  5. 公開投稿()
  6. {
  7. }
  8. public static void New( String PostText、 String PostHeader、 Int32 UserId)
  9. {
  10. DataBaseCore.DbModel m = new DataBaseCore.DbModel();
  11. DataBaseCore.Post p = new DataBaseCore.Post();
  12. p.Header = PostHeader;
  13. p.Text = Helpers.TypographText(PostText);
  14. p.PublishDate = DateTime .Now;
  15. p.User =(m.Userのusr から usr.Id == UserIdはusrを選択 ).First();
  16. m.AddToPost(p);
  17. m.SaveChanges();
  18. }
  19. public static void Delete( Int32 PostId)
  20. {
  21. DataBaseCore.DbModel m = new DataBaseCore.DbModel();
  22. DataBaseCore.Post p = new DataBaseCore.Post();
  23. p =(m.Postのpst から pst.Id == PostId select pst).First();
  24. m.DeleteObject(p);
  25. m.SaveChanges();
  26. }
  27. }
  28. }
*このソースコードは、 ソースコードハイライターで強調表示されました。




すべてがシンプルであるように思えますが、そうです。 しかし、いくつかのニュアンスがあります。

最初はLINQです。 それがなければ、ADO.NETはどこにもありません。 したがって、それを振り払って、一般にSQLまたはLINQでスコアリングするべきではありませんが、クエリを記述する必要があります。

第二に、このコードはフレームワークによって自動的に生成されるため、ある時点で特別な利便性を期待する必要はありません。また、スタジオで既に作成されたコードをいつでも変更する準備ができているはずです。 たとえば、ここの16行目では、データベースから選択する必要があるユーザータイプのオブジェクトではなく、ユーザーIDの値をすぐに送信する方が便利です。 したがって、このコードの方が便利ですが、普遍的ではありません。 したがって、コードを改良して再考する必要があります。 おそらく、ユーザーIDではなく、ユーザータイプのオブジェクトを渡すだけで済みます。



次は? さらに、ADO.NET Entity Frameworkのジャングルを掘り下げてプロジェクトを書き続け、Habrausersの皆さんと私の調査結果を喜んで共有します。 したがって、より深刻で詳細なデータを含む新しい記事があります。



UPD。 トピックは非常に広範囲です。 ここでは、可能性の割合は明らかにされていませんが、継続は8になります)






All Articles