Questions regarding the use of . dbml files

Asked

Viewed 290 times

3

I took a system in aspx(VS2008) and I will have to make some improvements, add other features and all this using MVC5. Well, there’s a web service, there’s a guy like that:

static Func<lqDataDataContext, T_PDV, IQueryable<T_PDV>>
            qryConsPdv = CompiledQuery.Compile(
            (lqDataDataContext lqPT, T_PDV p) =>
                lqPT.T_PDVs.Where(i =>
                    i.CNPJ.Contains(p.CNPJ) &&
                    i.RazaoSocial.Contains(p.RazaoSocial)//== (cnpj == "" ? i.CNPJ : cnpj)
                    ));

The question is that lqData is a .dbml. file. In my MVC I generated some .edmx. file The question is: Should I replace . dbml with . edmx? If yes, how to do this? I confess that I still do not understand the code posted. I know that dbml is like edmx, but what is the difference between both?

T_PDV is a bd entity. I don’t understand what delegate does. I am reading and interpreting the above code because I need to rewrite the site in MVC adding new features. This is my scenario today.

1 answer

3


  • edmx is the modeling file for the Entity Framework;
  • dbml is the modeling file for LINQ-2-SQL.

LINQ-2-SQL is a deprecated standard, so it is well recommended that you switch everything to edmx.

To convert, you basically have to follow the instructions of this link at MSDN.

About your CompiledQuery, works as follows:

  • IQueryable is an interface indicating an object that implements a collection of objects of the type T_PDV so that this collection can perform some operations through extension methods, as the method Where;
  • qryConsPdv, therefore, it is a delegate who operates upon a collection IQueryable<T_PDV> (one List<T_PDV>, for example) and asks for two arguments to work: the first is a lqDataDataContext (must be a data context) and the second is an object of type T_PDV;
  • Finally, what the delegate does is to check in its context whether the object passed as the second parameter of the delegate exists in the past context as the first parameter, checking if any object has the same CNPJ and the same Social Reason.
  • See that he uses the delegate FUNC<>. I would like to know the reason of the delegate, by the way, I have had difficulties with delegate. I’m really trying to understand the code above for me to redo my web service.

  • 1

    Well, that’s a new question, right? I think it’s in case you open up a new question.

  • That’s what I’d like to understand. It’s not a new question. As I said in the original post, I didn’t understand the code and it made the post. It is not a new doubt.

  • See, these are two very different questions. One is related to the use of files, and the other is related to understanding the code. So I think you should ask another question to get the answer only as to the doubt of delegate, which is pertinent. But I can answer that part also without problems, in the same ask if it is necessary.

  • Okay, of course I do. But look at the other side. You put a situation, whose problem is in several sectors. Gee, if you’re going to ask a question for each situation, it gets kind of repetitive, because often the code is the same. In a code we have many factors, which break down to ask a question for each will be asked, but repeating the code several times. Sometimes the question takes with it N doubts, like that for example, that a problem with dbml has led me not to understand why of delegate, queryable and etc.... All in the same doubt. downloaded something from queryable and delegate p/ read.

  • @pnet I updated the response.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.