# Dot net core web api Odata and Srp rule

**URL:** <https://community.sonarsource.com/t/dot-net-core-web-api-odata-and-srp-rule/141308>\
**Category:** SonarQube Cloud\
**Created:** [May 15, 2025, 11:28am UTC](https://community.sonarsource.com/t/dot-net-core-web-api-odata-and-srp-rule/141308 "2025-05-15T11:28:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![figuerres](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@figuerres](https://community.sonarsource.com/u/figuerres)\
**Post date:** [May 15, 2025, 11:28am UTC](https://community.sonarsource.com/t/dot-net-core-web-api-odata-and-srp-rule/141308/1 "2025-05-15T11:28:20Z")

</div>

I have a possible case where sonar is flagging a web api controller in error.  
we use azure devops for repositories and builds.  
the language is C# on dot net 8

i have a web api controller that has a method to use Odata / IQueryable on one method and that is beeing flagged for the SRP rule.

# This controller has multiple responsibilities and could be split into 2 smaller controllers.

Controllers should not have mixed responsibilities [csharpsquid:S6960](https://sonarcloud.io/organizations/teco-services-inc/rules?open=csharpsquid%3AS6960&rule_key=csharpsquid%3AS6960)

the controller has about 7 methods that all deal with the same entity.  
if i remove the one get the sonar issue is gone.

but that means that i will then need a second controller to have one method for the same entity.

the controller is a standard api controller on ControllerBase  
the method that triggers the message is like this:

```auto

[HttpGet]
[EnableQuery]
public IQueryable<WorItem> Get()
{
	return ctx.WorkItems;
}

```

ctx is an efcore context.

the controller also has a repository service that uses the same ef model.

i am wondering if that might be the source of the problem.

or if the scan just does not understand the option to have the enable query / odata option ?

---

<div class="post-metadata">

**Author:** ![figuerres](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@figuerres](https://community.sonarsource.com/u/figuerres)\
**Post date:** [May 15, 2025, 2:12pm UTC](https://community.sonarsource.com/t/dot-net-core-web-api-odata-and-srp-rule/141308/2 "2025-05-15T14:12:21Z")

</div>

found the solution to this.  
it was a problem with using both an ef context and a repository class in the controller. had to remove the use of the context and pull the data from the repository class…  
the repo uses the underlying context. at first i did not see that as an issue.

the srp error in sonar did notmention the data source issue and the code worked… so it was confusing.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [May 22, 2025, 2:12pm UTC](https://community.sonarsource.com/t/dot-net-core-web-api-odata-and-srp-rule/141308/3 "2025-05-22T14:12:55Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
