2

im use This Query T-SQL

SELECT [Extent1].[ProductAttributeCombinationId] AS [ProductAttributeCombinationId], [Extent1].[ProductId] AS [ProductId], [Extent1].[ProductAttributeXML] AS [ProductAttributeXML], [Extent1].[StockQuantity] AS [StockQuantity], [Extent1].[Price] AS [Price] FROM [dbo].[ProductAttributeCombination] AS [Extent1] WHERE N'' = cast([Extent1].[ProductAttributeXML] as nvarchar(max))

Can this Query To LINQ?

Reza Bahari
  • 104
  • 7

1 Answers1

1

You can use Linqer for that.

Linqer is a SQL to LINQ conversion tool. It helps learning LINQ and convert existing SQL statements.

Not every SQL statement can be converted to LINQ, but Linqer covers many different types of SQL expressions. Linqer supports both .NET languages - C# and Visual Basic.

Because LINQ is a part of the C# and VB languages, it is sensitive to data type conversion. Linqer performs required type castings in the produced LINQ statements.

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • im use linqer the result query : from Extent1 in db.ProductAttributeCombinations where "'" == SqlFunctions.StringConvert((Double)Extent1.ProductAttributeXML) select new { ProductAttributeCombinationId = Extent1.ProductAttributeCombinationId, ProductId = Extent1.ProductId, ProductAttributeXML = Extent1.ProductAttributeXML, StockQuantity = Extent1.StockQuantity, Price = Extent1.Price } – Reza Bahari Apr 26 '16 at 19:43
  • Not clear what is your issue here. Can you tell us ? – Sampath Apr 26 '16 at 19:46
  • the result query in linqer not worked and error message is : " Error Compiling Expression: Error Compiling Expression: Delegate 'System.Func' does not take 1 arguments Cannot convert lambda expression to type 'string' because it is not a delegate type Cannot convert type 'string' to 'double' " – Reza Bahari Apr 26 '16 at 19:48
  • Did you test the `linqer` with simple example ? check whether is that installed and configured correctly. – Sampath Apr 26 '16 at 19:51
  • Yes the sql query converted to linq with linqer but not worked There was another way – Reza Bahari Apr 26 '16 at 19:53
  • If it's not working for a simple query itself then you have not installed it correctly ? – Sampath Apr 26 '16 at 19:58
  • im download trial version from site, Might be an issue be? – Reza Bahari Apr 26 '16 at 20:00
  • Trial versions are working correctly.Try to install it again after removing the current installation. – Sampath Apr 26 '16 at 20:01
  • Worked in Linq To SQL but when To Select LINQ TO ENTITY Difrents Result View – Reza Bahari Apr 26 '16 at 20:17
  • the result for LINQ TO SQL : from Extent1 in db.ProductAttributeCombination where "'" == Convert.ToString(Extent1.ProductAttributeXML) select new { ProductAttributeCombinationId = Extent1.ProductAttributeCombinationId, ProductId = Extent1.ProductId, ProductAttributeXML = Extent1.ProductAttributeXML, StockQuantity = Extent1.StockQuantity, Price = Extent1.Price } this worked – Reza Bahari Apr 26 '16 at 20:17
  • [Column(TypeName = "xml")] [Required] public string ProductAttributeXML { get; set; } The Model in Code First – Reza Bahari Apr 26 '16 at 20:24
  • this is propery of model in EF CodeFirst and Difference Result in Linqer when use linq to entity converted is : from Extent1 in db.ProductAttributeCombinations where "'" == SqlFunctions.StringConvert((Double)Extent1.ProductAttributeXML) select new { ProductAttributeCombinationId = Extent1.ProductAttributeCombinationId, ProductId = Extent1.ProductId, ProductAttributeXML = Extent1.ProductAttributeXML, StockQuantity = Extent1.StockQuantity, Price = Extent1.Price } – Reza Bahari Apr 26 '16 at 20:30
  • The error Message : Error Compiling Expression: Error Compiling Expression: Delegate 'System.Func' does not take 1 arguments Cannot convert lambda expression to type 'string' because it is not a delegate type Cannot convert type 'string' to 'double' Delegate 'System.Func' does not take 1 arguments Cannot convert lambda expression to type 'string' because it is not a delegate type Cannot convert type 'string' to 'double' – Reza Bahari Apr 26 '16 at 20:31
  • adjust those things manually. That tool does not support all data types. – Sampath Apr 26 '16 at 20:32
  • Can Use EdmFunction cast xml to nvarchar(max)? – Reza Bahari Apr 26 '16 at 20:39
  • may be helped to you :http://stackoverflow.com/questions/13958195/cast-for-xml-to-varcharmax – Sampath Apr 26 '16 at 20:43