Problem refreshing tables in the LINQ to SQL designer

后端 未结 9 1432
野趣味
野趣味 2021-02-08 12:54

I have been using LINQ to SQL for a while, and there is one thing that has always bothered me. Whenever I modify the schema of a table, in order to refresh it in the designer, I

相关标签:
9条回答
  • 2021-02-08 13:10

    I have had simliar issues with the designer - the best thing I can suggest is creating multiple contexts for different areas of your data access - I broke mine down to as few a related tables as I could get away with for each functional area. You can re-use tables across contexts so it isn't a big deal.

    0 讨论(0)
  • 2021-02-08 13:13

    Some people use SqlMetal to 'refresh/update' their Linq2Sql designer. The designer does not have support for refreshing the schema, when the DB changes. You have to manually drop the table and re-add it back in.

    ADO Entity Framework i believe can refresh. I've not used it, but I think I saw this at a TechEd demo this year.

    Helpful Info: Google's results for SqlMetal.

    0 讨论(0)
  • 2021-02-08 13:15

    There's a template for VS 2008 that replaces the designer, it should ease refreshing your LINQtoSQL classes: http://damieng.com/blog/2008/09/14/linq-to-sql-template-for-visual-studio-2008

    0 讨论(0)
  • 2021-02-08 13:17

    I personally detest using the designer, and I've had various issues with it whenever I've dared to use it.

    I mostly use LINQ for very simple CRUD (no linked entities or anything), and if that's the case with you, it might be worth straying from the designer crutch. Especially since defining LINQ-to-SQL entities is as easy as this:

    [Table("dbo.my_table")]
    public class MyTable
    {
    [Column("id", AutoSync = AutoSync.OnInsert, IsDbGenerated = true, IsPrimaryKey = true)]
    public Int32 Id { get; set; }
    
    [Column("name", DbType="NVarChar(50) NOT NULL")]
    public String Name { get; set; }
    }
    

    This way, all your entities have their own files, which makes finding them much easier, though you'll still have to add/update the properties manually.

    Of course, if you'd refactor 100+ tables, that might not be an option ;)

    0 讨论(0)
  • 2021-02-08 13:20

    This is not possible using the VS linq to sql designer.

    You can do this using LLBLGEN PRO, a third party tool, instead of the built-in linq to sql designer. It isn't free but it does do a ton of other stuff as well, which of course you may or may not need.

    LLBLGEN PRO is actually a full set of ORM tools, but also includes an enhanced linq-to-sql designer with 'refresh model from SQL' functionality.

    See here for description of the issue - http://weblogs.asp.net/fbouma/archive/2008/05/01/linq-to-sql-support-added-to-llblgen-pro.aspx And here for the tool - http://www.llblgen.com/

    0 讨论(0)
  • 2021-02-08 13:25

    I have a similar comment, thought it might fit in here for anybody out there Googling a solution to this issue...

    When I change the columns that are returned by a stored procedure, deleting the procedure from the designer and re-adding it does not work. The custom return type entity that the designer generates does not reflect the changes to the SP.

    I've tried disconnecting the DB in the server explorer, even deleting and re-adding the connection.

    The only solution I've found is this: 1. Delete the SP from the designer. 2. Save the dbml file (or the whole solution, whatever) 3. Completely close Visual Studio. 4. Re-open Visual Studio and your solution. 5. Re-add the stored procedure to the designer.

    I think that qualifies as a blue ribbon pain in the rump. Anybody got a simpler solution?

    PS- To those of you with 100+ tables: Go get a real (real == mature) ORM tool. I personally vote for NetTiers. It rocks. Used it for years with no (or at least very few) complaints. You'll probably have to buy CodeSmith to use it effectively, but it's worth it. The templates are open source. And there are templates for nHibernate as well. But I've found that I don't really dig on Java ports. If I'm gonna code on MS platforms I want code that was "born" there...

    ...editorial complete. :P

    0 讨论(0)
提交回复
热议问题