CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

John Papa [MVP C#]

.NET Code Samples, Data Access, and Other Musings

March 2007 - Posts

  • April Fools Day Idea - Coding For Fun

    Being the mischievous sort that I am, I am always interested in a creative (yet harmless) prank. A friend of mine, Brian Peek, is a master at creating interesting hardware based solutions with .NET. Recently he has come up with some great ideas for the holidays such as an application that will drip blood on a computer screen, his motion detecting blood squirting skull, or the less demonic and more cheerful Holiday light show. Brian also has several other neat ideas (some of which involve minor hardware and some of which do not) that he writes about in his column with MSDN Coding For Fun.

     

    Anyway … Brian came out with a neat idea for an April Fools Day joke. The article in Coding For Fun that Brian wrote describes how to make an application lay in wait til an assigned day and time and then it will take a screenshot of the monitor(s) and rotate then and/or zoom them in and out. I won’t give out all of the details here as Brian did a great job at explaining them in his article. All of the code is included in both VB and C# and it requires nothing but .NET. So go check out his article and stay away from my computer!

     

    Oh … and I love the disclaimer message that appears when you download the code. It basically says you run this at your own risk J I guess they were covering themselves in case Brian was the next great virus creator. Can’t blame them really. But it is funny J

     

     

     

    Rotating Screen for April Fools Day

     

     

     

    Motion Detecting, Blood Squirting Skull

     

     

     

     

     

    Posted Mar 31 2007, 10:54 AM by John Papa with 1 comment(s)
    Filed under:
  • Wash Your USB Flash Memory Stick

    Let me start by saying that I have been working some crazy hours lately and I am battling a fierce springtime cold. OK, so there is my lame excuse …. I left my 2GB USB flash stick in my shirt pocket and threw it in the wash today. My wife just folded the laundry and brought the poor soul out to me to give me the bad news. Now this thing just went through the washing cycle and was inundated with water. It went through the drying cycle which gets so darn hot that I have had other plastics melt in it. Oddly enough the USB stick came out looking pretty good, (and much cleaner).

     

    I put the stick in my computer hoping for the best …. and it still works!

     

    The moral of the story? Don’t throw out those old USB keys because they are dirty, just throw them in the washing machine!

     

  • Entity Framework Thoughts

    I agree that there is quite a bit of work to do yet with the Entity Framework. Earlier today Scott posted his thoughts on the challenges that the Entity Framework faces. He makes some good points which really show how the approach to application development greatly influences which tools and development strategies developers will choose. I agree that applications have a better chance to succeed when they are "business rule" driven.

    I prefer to build a data model and a business model together, not one before the other. In its current state the Entity Framework can be generated from an existing data model (or can be created by hand with XML). The data team at Microsoft knows this is a limitation and is working on solutions to make building and tweaking entities, mapping the conceptual model to a logical model, and overall design of the EDM much more fluid. I am very excited about seeing what they produce on this end.

    Building off of the example that Scott worked, assume you have an entity that you are working with and realize that you need to add a new property (or field) to it to establish a business rule (or to write a test if you are using TDD).  You want to add the field or property to the entity and keep moving along with your business rule (probably using Resharper or the like to create the field/property combination). The idea is to keep your brain patterns flowing with the business rule and not to step outside of tat to implement a new field/property and populate it. You want to create the additional property, use it in your code, and map it to the models quickly.

    With the Entity Framework in its current state you could add a new partial class and add the field and property to it, but then you are deviating from the EDM with a field that you will eventually want to persist in the database anyway. Another option with the Entity Framework is to add the property to the conceptual model and mapping it to a database field (that you must create). This is an option that  makes sense but is the most difficult to implement at this time. I believe this is one area where the Entity Framework has room to grow and the data team can add more value to the development community: Having a way to easily amend business entities, have it flow through the conceptual model ,and map them to a logical model to the database.

    There is a lot left to work out and the more people who use the Entity Framework, participate in the forums, test the CTP’s, and provide feedback where they can, the better the end result will be. I believe that the data teams at Microsoft are absolutely committed to this technology and I am personally very excited about the Entity Framework ….. more excited than I have been about a technology in a long, long time.

  • Stored Procedures and CUD (minus the R) in the Entity Framework

    The Data Access Team published a great post that has some superb explanations on how to make the Entity Framework use stored procedures for inserts, udpates and deletes. (It does not yet support stored procedures for retrieving data.)   Obviously there are pieces missing, as Shyam states (such as retrieving data via sprocs), but to see CUD (minus the R) working in the EF with sprocs is great.

    One knock I can already hear though is how people will have to change the existing sprocs. Specifically in the example where the additional parameter must be added to support the EF's  determination of which entities/sprocs to execute in which order. Obviously it would be better if a future evolution could do without this.

    Fantastic to see sproc support born in the Entity Framework!

    On a related note, I am having a heck of a time trying to get an overview of ADO.NET Orcas to fit into a publishable article. There is just sooooo much to it and so little space to write about it. I could go on for days on this topic :)

  • Disabling Constraints and Triggers

    My April 2007 Data Points column has been posted to the MSDN Magazine web site. This edition is titled "Disabling Constraints and Triggers".

     

     

    Posted Mar 14 2007, 09:05 AM by John Papa with no comments
    Filed under:
  • LINQ to Entity Samples added to 101 Samples!

    Earlier in March I posted that some samples intended for use with the March CTP of Orcas were available for download. These samples replace the samples that are linked from the MSDN docs in the CTP. One thing these samples lacked was the LINQ to Entities samples. Today, Charlie Calvert posted a link to updated samples that include LINQ TO Entities samples inside the SamplesQueries example project. Inside the SamplesQueries project you will find a 101 LINQ to Entities samples.

    This is great news! Previously there were tons of examples in this project for LINQ to SQL, LINQ to XML, LINQ to Objects and LINQ to DataSets. With the additin of LINQ to Entities, it means I have plenty of material to play with and keep my head buried in ADO.NET and the Entity Framework.

     

    You can download the new samples here.

  • Entity Framework and Object Services Primer

    As I am sure you have read by now, the Entity Framework is a huge leap forward in the next iteration of ADO.NET in Orcas.  Currently the implementation has a conceptual layer represented by a CSDL file. This CSDL file contains the XML that represents conceptual model (the objects). The conceptual layer is mapped to the database through a series of lower layers (the Mapping and the Source). The Source is represented by a SSDL file which contains XML that represents the database schema. The MSL file contains the XML that maps the CSDL to the SSDL. All 3 of these files can be generated using the EDM Model Wizard in the Orcas Feb/March CTP.

    Once the model has been generated (or created by hand), the data can be manipulated and interrogated through the conceptual model. Thus a level of abstraction is created where an application can interact with data through an object model that is mapped to the underlying data source. LINQ to Entities or Entity SQL can be used to interact with the EDM. LINQ to Entities is great when you can define your query expressions at design time and enhance them with parameters. Entity SQL can also be sued to achieve the same goals, however since Entity SQL is string based it can support more dynamic queries where queries can be built on the fly.

    There is quite a bit to chew with the Entity Framework, more than enough for a entire series of articles. And I have not even touched on the other ADO.NET components such as LINQ to SQL or LINQ to DataSets, much less the designers, LINQ to objects, LINQ to XML, EntityClient and much much more.

    It is an exciting time to be involved with data access technologies! And some unforeseen changes are yet to come as many have already experienced the changes through the CTP’s of LINQ and Orcas. But it seems evident that the data access team is making its biggest change to data access in a very long time.

    Entity Framework

  • Updated Samples for Orcas March 2007 CTP

    Charlie Calvert has posted some samples intended for use with the March CTP of Orcas. These samples replace the samples that are linked from the MSDN docs in the CTP (which is good since I have had mixed result wth them so far). Charlie also posted a video on the samples here that helps explain them.

     

  • Entity Framework Terminology

    I have some articles to write on the Entity Framework and LINQ to ADO.NET, so I will be busy in the depths of EF for a while. I have been spending the past few days immersing myself in the Orcas March CTP. While there are features I am still longing for (such as the EDM Designer) this is the most EF & LINQ complete CTP in a long time. While the MSDN Documentation is not complete by any means, there is some great information in there. For example, I found this fantastic page in the help docs that is a glossary of the Entity Framework terminology. I pulled this directly from their documentation, which you can find at this link (ms-help://MS.MSDNQTR.v90.en/MS.MSDN.v90/MS.VisualStudio.v90.en/WD_ADONET/html/fa2a1bd1-6118-487b-8673-eebc66b92945.htm ) in the March CTP's help docs. This is a great reference to lean on when learning the EF ... kudos to the data team for creating and including this information in the CTP.

     

    Entity Framework terminology:

    alias

     An attribute of the Schema element in CSDL and SSDL schemas that can be substituted for the full namespace to shorten element references in the schema.

    association

     The definition of a relationship between entity types.

    association set

     A logical container for instances of associations of the same type.

    base type

     A parent type or super-type in the EDM from which derived types inherit some of their properties.

    complex type

     An entity type whose properties have internal properties. Used as a property of an entity type or of another complex type.

    conceptual schema definition language (CSDL)

     XML-based dialect used to define the entity types, associations, entity containers, entity sets, and association sets of a conceptual model.

    conceptual model

     Abstract specification for the entity types, associations, entity containers, entity sets, and association sets comprising an application domain.

    constraint

     Restricts the possible values of a property and ensures that a value is valid.

    container

     A logical grouping of entity and association sets.

    degree

     The number of entity types in a relationship. Relationships are classified as unary, binary, ternary, or n-ary.

    direction

     Refers to the asymmetrical nature of some associations. Direction is specified with FromRole and ToRole attributes of ReferentialConstraint elements in entity data models.

    end

     A participating entity in an association.

    entity

     An instance of an entity type.

    EntityClient

     A storage-independent ADO.NET data provider containing classes such as EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage specific ADO.NET Data Providers, such as SqlClient.

    entity container

     Specifies the sets of entity types and associations that will be available in a specified namespace.

    Entity Data Model (EDM)

     A system for defining application data as sets of entities and relationships.

    Entity Framework

     A set of technologies that supports development of data-oriented software applications by allowing developers to work with conceptual models that are mapped to logical schemas in data sources.

    entity-relationship model

     A data model that uses relationships between entities as the basis for describing application data schemas.

    entity set

     A logical container for entities of the same type, mapped to tables in a database.

    Entity SQL

     A storage-independent dialect of SQL that works directly with conceptual entity schemas and that supports entity data model features such as inheritance and relationships.

    entity type

     A named set of properties representing a top-level item in a data model.

    enumeration

     A simple type whose single value is selected from a specified set of options.

    facet

     A constraint, such as Nullable, MaxLength, or Precision, that limits the allowable values for a property.

    helper method

     User-defined operations implemented in partial classes that add functionality to objects generated from entity data models.

    key

     The attribute of an entity type that specifies which property or set of properties is used to identify unique instances of the entity type.

    language integrated query (LINQ)

     A query syntax that defines a set of query operators that allow traversal, filter, and projection operations to be expressed in a direct, declarative way in C# and Visual Basic.

    LINQ to Entities

     The use of language integrated query operators with objects representing a conceptual model.

    mapping

     A set of correspondences between items in a conceptual model and items in a storage model.

    mapping specification language (MSL)

     An XML-based dialect used to map items defined in a conceptual model to items in a storage model.

    metadata

     Data used to describe the structure of other data, including the SSDL XML file, which describes the structure of data in a data store.

    Metadata Workspace

     A class that represents the metadata runtime service component that provides support for retrieving metadata.

    multiplicity

     The number of entities that can exist on each side of a relationship.

    navigation property

     A property of entity types that uses an association to reference related entities.

    object services

     Services provided by the Entity Framework to classes generated from a set of metadata.

    object context

     A base class that provides object services such as tracking and saving changes, and that contains a connection to the underlying data store.

    referential constraint

     An element of an SSDL entity data model that specifies the direction of an association with FromRole and ToRole attributes. Corresponds to a CSDL navigation property.

    relational model

     The logical model used to define the tables, columns, and constraints in a database.

    relationship

     A logical connection between entities.

    role

     The name given to each end of an association to clarify the semantics of the relationship.

    simple type

     Primitive type used for defining properties in entity data models.

    store schema definition language (SSDL)

     XML-based dialect used to define the entity types, associations, entity containers, entity sets, and association sets of a storage model, often corresponding to a database schema.

    table-per hierarchy (TPH)

     A method of modeling a type hierarchy in a database that includes the attributes of all the types in the hierarchy in one table.

    table-per-type (TPT)

     A method of modeling a type hierarchy in a database that uses multiple tables with one-to-one relationships to model the various types.

    XML (simple type)

     Can contain well-formed XML or valid XML data. The facets of this type control which kind of XML data can be contained within it.

More Posts