What are the advantages or disadvantages of using dbml for linq2sql queries?

I am currently reading Pro Asp.Net MVC and they build all their linq2sql object classes manually and map them to linq display attributes. However, everyone I see (from Google searches) talking about linq 2 sql seems to use the visual designer to create all of their objects. What is the preferred way to create l2s objects and what are the advantages / disadvantages of each?

The only difference that I have noticed so far is that I cannot render the inheritance when using the visual constructor, although MSDN says that I should be able to, so I can just skip it in the VS 2010 interface. however, I'm not sure that I should use inheritance anyway, as this can technically add extra joins when I don't need subcategory data.

As a PS, l2s will not make any changes to my schema, I will generate the schema changes manually and then replicate them to linq2sql.

Thanks,

+4
source share
2 answers

We used the designer all the time. It really introduces an extra step, every time you make changes to the schema, you need to import the table into the constructor again, but I think the effect fades compared to the amount of code you need to write if you bypass the desginer.

Also note that the constructor creates partial classes, you can create an additional file for the partial class, which includes additional implementation details. Thus, when the table receives the referee in the designer, it leaves you additional code. We do this by adding many helper functions to the classes, and we also provide strongly typed listed properties that overlap the primitive FK fields.

It is true that inheritance will be very difficult to do well, but I think that if you need this type of data, L2S might not be the best solution. I prefer my data layer to be clean and simple, just using L2S ​​to input and output data, and then more complex logic in the business layer. If we really needed to do something like inheritance of objects in our data layer, I would probably investigate more complex and complex technologies such as EF

+2
source

We created the entire backend of the application platform using L2S. I designed most of this. I started using the DBML constructor, but I quickly realized that it was a royal pain. For each change in the scheme, a change in the table (s) in the designers is required. In addition, the entities created by the designer are all populated in one class file and do not have all the necessary functions, such as supporting M2M relationships, etc. So it didn't take long before I realized that I needed a better way.

I ended up writing my own code generator that generates L2S entities the way I want them, and also generates a "light" set of objects that are used in the application layer. They do not have a L2S water pipe. The code generator creates all of these entities and other code directly from the target database. No more DBML!

This worked very well for us, and our entities are exactly the same as we want them, and are generated automatically every time our database schema changes.

+1
source

Source: https://habr.com/ru/post/1301230/


All Articles