I got a system in aspx (VS2008) and I have to make some improvements, add other features and all this using MVC5. Well, there’s a web service, which has 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 point 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 dbml is like edmx, but what’s the difference between them?
T_PDV is a DB entity. I did not understand what the delegate does. I am reading and interpreting the above code, since I need to rewrite the site in MVC adding new features. This is my scenario today.
- edmx is the modeling file for the Entity Framework;
- dbml is the modeling file for LINQ-2-SQL.
LINQ-2-SQL is a deprecated pattern, so it’s well recommended that you change everything to edmx .
To convert, you basically have to follow the instructions of this link on MSDN.
CompiledQuery , it works as follows:
IQueryableis an interface that indicates an object that implements a collection of objects of type
T_PDVsuch that this collection can perform some operations through extension methods , such as the
qryConsPdv, so it is a delegate that operates on top of a collection
List<T_PDV>, for example) and asks for two arguments to work: the first is
lqDataDataContext(must be a data context) and the second is an object of type
- Finally, what the delegate does is check in its context if the object passed as second parameter of
delegateexists in the context passed as the first parameter, checking if any object has the same CNPJ and the same Social Reason.