CodeSmith Community
Your Code. Your Way. Faster!

Linq to SQL Questions

Latest post 01-09-2008 3:49 PM by pwelter34. 7 replies.
  • 08-02-2007 10:00 AM

    • CHarker
    • Top 75 Contributor
    • Joined on 10-03-2004
    • Posts 59
    • Points 880

    Linq to SQL Questions

    Having got my 4.1 version and looked at Linq to Sql I have several questions.

    1) What is it and what does it do?  I guess it does the same as the code behind tool in Orcas (SqlMetal). Correct?  Is it better or worse? Is it Orcas compatible? What do these properties do?

    2) I can't pick my tables. True? It's all or nothing

    3) I can't do Stored procedures. When I ran it nothing about Sp's appeared.

    4) What are managers?

    5) Where is the help?  There are no comments in the code either and not even a descent readme

    6) What are these mappings in the code?

    7) Can I have fields names and column names mapped?

    Forgive me for sounding ungrateful but someone has spent many hours building this template and as it stands I will have to spend as many hours again unpicking it to work out what it does and how I can use/enhance it.  So what's the point of it?  Could the author please enlighten us to his efforts and explain the thing?

    What does it give me that the SQLMetal doesn't?

    Please someone tell me....

    Cliff

     

    • Post Points: 35
  • 08-02-2007 12:47 PM In reply to

    • pwelter34
    • Top 25 Contributor
    • Joined on 03-13-2003
    • Eden Prairie, MN
    • Posts 255
    • Points 680,955

    Re: Linq to SQL Questions

    Reply |Contact |Answer

    Hi,

    Sorry about the sparse information with the templates.  The templates are a work in progress.  I'm working on a tutorial to help get you started.  I should have it done soon.  I'll give you some quick answers to you questions.

    1) Yes, the templates do the same as the Linq to Sql designer and SqlMetal.  Having templates allows you the ability to tweak the output (classes) to your liking.  Also, the templates generate one class per file, instead of all the classes in one file as SqlMetal does.  The tutorial will further document the properties on the templates.

    2) Yes, you can not pick tables.  This is because there are foreign keys between tables and things may not work correctly with out all the tables.  In a future release, there will be an ability to ignore tables.

    3) Stored procedures are not supported yet.  However, a future release will support them.

    4) Managers are classes that contain common queries and rules for an entity.  They are fairly basic at this point but will grow to become the place to store business logic and rules for entities. You can think of them as an extension to the Linq to Sql entities.

    5) Sorry, no help yet.  As mentioned, I will be doing a tutorial.  I will try to comment the templates better as well.

    6) By mapping, I am talking about the map between the table and the class.  This information is stored in the dbml file.  This is the same file that the Linq to Sql designer uses in Visual Studio 2008.  The Dbml.cst template is used to generate this file.  You can edit the file to rename classes and properties if you wise.  In the tutorial, I will explain more on how to do this.

    7) I'm not sure what you mean by this.  The template will create a property for every column in a table. 

    Hope that helps give you some basic answers.  The tutorial will help a lot more.

    ~ Paul

    Filed under:
    • Post Points: 35
  • 08-02-2007 1:45 PM In reply to

    • CHarker
    • Top 75 Contributor
    • Joined on 10-03-2004
    • Posts 59
    • Points 880

    Re: Linq to SQL Questions

    Thanks for a quick reply. By (7) I mean the mapping of names which is covered by (6) also.

    Also I failed to find the "CodeSmith.Data" dll's used in the "using" lines. Where do they live? 

    My usual angle on these things is ease of use in large developments. Microsoft always fail to scale up in the tools. This designer of theirs has no “refresh” option on a table, requiring the table to be deleted and re-added and no doubt needing all the column names re-changing etc. Just not good enough if you ask me!

    My last development where we used Codesmith we had over 400 tables and many DB developers (not knowing anything about C#) changing the data model frequently. Using my templates we generated 2m lines of code sometimes 3 times a day. I have been asked to move this forward to .NET 3 and use the latest techniques.

    You say you generate the mapping file. Do you do this every time? Would changes to it get overwritten? Do you “merge” changes like you do with the project file?

    We had to auto generate the mappings, the database used underscores (historical reasons) and we wanted Pascal casing. So we removed underscores and capitalised the next letter.  Being able to plug-in a translation method for the table and field names would be good.  Manually specifying 400 tables and 1000's of fields would be error prone and tedious. Also when schema changes are made we would have to hand edit the mapping file to ensure new fields were named and kept in sync and we may not know which fields they are!  We need changes to merge and have the correct naming to make life easy :)

    Being able to exclude tables is also good. Obviously the same for SP's would be needed. I suppose if you exclude the related table to drop the relationship from the code. I was thinking more about orphan tables (temp tables, ref data tables etc) that have no relations.

    I'm not sure the MSoft gen covers this but my templates generated entities for the SP's.  There was a results entity from an SP that returned a record set (rather than a plain dataset like NetTiers) and also a entity (of the parameters) for an SP that did an update. What does SQLMetal do, Do you know?

    I'm sure I could think of some more :)

    Keep up the good work, I look forward to seeing future releases, it may save me lots of work :))

    Cliff

     

     

     

     

     

    • Post Points: 65
  • 08-08-2007 12:58 PM In reply to

    • pwelter34
    • Top 25 Contributor
    • Joined on 03-13-2003
    • Eden Prairie, MN
    • Posts 255
    • Points 680,955

    Re: Linq to SQL Questions

     Hi,

    I have a post up to document the templates.  There is a new version with a lot more features as well.

    Features

    The templates have the following features.

    • Generate or update a LINQ to SQL dbml file from a database schema.
      • Includes all tables, stored procedures, functions, and views with the ability to exclude objects based on regex patterns.
      • Ability to automatically remove object prefix and suffixes (ie. tbl_ and usp_).
      • Dbml file can still be customized with the normal Visual Studio 2008 designer.
      • Dbml file can be refreshed based on the current database schema without losing customizations. (See Safe Attributes)
    • Generation of the LINQ to SQL DataContext class.
    • Generation of the LINQ to SQL entity classes.
      • Generates one file per entity instead of one massive file.
      • Generates partial classes where custom code can be written and won't be overwritten.
      • Generated entity files are added to the project as code behind files to their corresponding custom entity files.
    • Generation of entity manager classes.
      • Adds customizable business rules engine to enforce entity validation, business and security rules.
      • Provides access to common queries based on primary keys, foreign keys, and indexes.
      • Common queries are exposed as IQueryable so they can be extended.
    • All templates can be customized to meet your needs.

     

    http://community.codesmithtools.com/blogs/pwelter/archive/2007/08/03/plinqo.aspx

     ~ Paul

    Filed under:
    • Post Points: 5
  • 08-20-2007 6:12 PM In reply to

    • wgpubs
    • Not Ranked
    • Joined on 08-20-2007
    • Posts 5
    • Points 85

    Re: Linq to SQL Questions

     I'm getting the can't find Codesmith.Data exception as well.  

     Where the hell is it?  And why is it being used?
     

    • Post Points: 35
  • 08-21-2007 2:01 PM In reply to

    • pwelter34
    • Top 25 Contributor
    • Joined on 03-13-2003
    • Eden Prairie, MN
    • Posts 255
    • Points 680,955

    Re: Linq to SQL Questions

    Hi,

    The CodeSmith.Data project is included in the zip file of the latest version.  Sorry I forgot to mention this in the post.  It is needed by the manager classes for Business rule support.

    ~ Paul 

    • Post Points: 35
  • 01-09-2008 2:10 PM In reply to

    • joswalt
    • Not Ranked
    • Joined on 04-19-2006
    • Posts 1
    • Points 35

    Re: Linq to SQL Questions

    Are these templates still being developed? There is all kind of bugs in the template. I get a ton of errors in my dbml designer file about partial methods already declared in my data generated classes. The same for properties being alread declared. Anyone have ideas or able to get this template to work?

     Thanks,

    Filed under: ,
    • Post Points: 35
  • 01-09-2008 3:49 PM In reply to

    • pwelter34
    • Top 25 Contributor
    • Joined on 03-13-2003
    • Eden Prairie, MN
    • Posts 255
    • Points 680,955

    Re: Linq to SQL Questions

    Hi,

    There have been updates made.  Please download the latest commited version.  See if that resolves your issues.  If not, let me know and i will fix the bugs.

    ~ Paul 

    • Post Points: 5
Page 1 of 1 (8 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems