I am using linq to sql framework in my C# code. I would like to implement query pattern for a scenario ( check if a given organisation is valid). how can this be done without using data context. I do not want to use or create a data context for the table which i want to check my scenario.
Asked
Active
Viewed 328 times
-1
-
It's very unclear what you're trying to achieve. A data context *is* how you access the data in LINQ to SQL. Please clarify your question. – Jon Skeet Jun 13 '16 at 08:28
-
ok.. i have added a new schema and table into my db. now i wish to access this schema table from my code without having to add this new schema into my code.i need to check this new table if an organisation exists or not – V. B Chan Jun 13 '16 at 08:33
-
So use plain SQL, or maybe LINQ to DataTables. I don't see how you would expect to use the normal LINQ to SQL approach to querying, which relies on having the schema in a strongly-typed form in your object model, without having that schema information present. *Why* don't you want to create a data context? *Why* don't you want to add the new schema to the code? – Jon Skeet Jun 13 '16 at 08:34
-
yes i do understand.. but i need to implement the query pattern mandatory.. hence the question.. as per our coding standards we are not allowed to add new schemas further on..as we are trying to migrate to a new framework – V. B Chan Jun 13 '16 at 08:35
-
@VBChan: Then you need to add the schema to your code. It's as simple as that. How do you expect the compiler to know what properties etc are available if you're unwilling to give it that information? – Jon Skeet Jun 13 '16 at 08:36
-
if exists (select * from scemaname.tablename where Code = @Code) begin select 1 as Exist; end else begin select 0 as Exist; end – V. B Chan Jun 13 '16 at 08:42
-
i want this SP to be implemented as query pattern in my code – V. B Chan Jun 13 '16 at 08:42
-
Okay, so how do you expect the compiler to know that `Code` is a valid field name when you're unwilling to give it that information? Presumably you'd want the code to fail to compile if you made a typo of "Code2" for "Code", right? I think maybe you need to learn more about how LINQ to SQL works to understand why what you're asking doesn't make much sense. – Jon Skeet Jun 13 '16 at 08:43
-
@JonSkeet yes i now understand what you were trying to imply. Many thanks for giving me a clear picture – V. B Chan Jun 29 '16 at 09:58
1 Answers
0
Do you want raw sql execute like this?
var blogNames = context.Database.SqlQuery<string>("SELECT Name FROM dbo.Blogs").ToList();

İlker A.
- 11
- 5
-
yes i need something like this.. but want to ensure that query pattern is implemented – V. B Chan Jun 13 '16 at 08:34